Попытка проверить пользователя с помощью токена, но emailAddressVerificationToken не определен - PullRequest
0 голосов
/ 13 января 2019

Я пытаюсь подтвердить пользователя, нажав на ссылку электронной почты через sendgrid. Ниже вы можете увидеть код, который я пытаюсь передать values.emailAddressVerificationToken, чтобы он передавался в мой файл действий, однако я получаю emailAddressVerificationToken неопределенным внутри моего компонента проверки.

enter image description here

проверить компонент

  import { verifyEmailSubmit } from "../../stores/Auth/actions";
    // gets the token in the URL
    getVerifiedEmailToken = () => {
    const query = parse(this.props.location.search);
    return query.token;
  };

     componentDidMount(values) {
        // this means the user has clicked the link, so we'll verify the email here
        const { verifyEmail } = this.props;
        console.log(verifyEmail);
        console.log(values);
        values.emailAddressVerificationToken = this.getVerifiedEmailToken();
        verifyEmail(values);
      }

    const mapDispatchToProps = dispatch => ({
      verifyEmail: params => dispatch(verifyEmailSubmit(params))
    });

    export default withRouter(
      connect(
        mapStateToProps,
        mapDispatchToProps
      )(VerifyEmailComplete)
    );

файл действий авторизации

    export function verifyEmailSubmit(params) {
      const mutation = `
      mutation {
        verifyEmail(
          emailAddressVerificationToken: "${params.emailAddressVerificationToken}"
        )
      }      
    `;

      return dispatch => {
        dispatch(authInProgress());

        return ApolloService.mutate({ mutation })
          .then(response => {
            const { verifyEmail } = response.data;

            dispatch(resetAppMessages());
            dispatch(verifyEmailSuccess());
            return verifyEmail;
          })
          .catch(error => {
            dispatch(verifyEmailFailure());
            // Need to throw this error so that the callee (react component) can use this error in it's own catch block
            throw error;
          });
      };
    }

1 Ответ

0 голосов
/ 13 января 2019

Эта ошибка связана с этой строкой в ​​componentDidMount

values.emailAddressVerificationToken = this.getVerifiedEmailToken();
// values is undefined. react don't send any argument

componentDidMount не отправляйте никаких аргументов, и вы принимаете аргумент, из-за которого значение values не определено. Пожалуйста, обратитесь здесь

...