【问题标题】:Trying to verify user with token but emailAddressVerificationToken undefined尝试使用令牌验证用户但 emailAddressVerificationToken 未定义
【发布时间】:2019-06-07 14:03:09
【问题描述】:

我正在尝试通过 sendgrid 单击电子邮件链接来验证用户。您可以在下面看到我正在尝试传递 values.emailAddressVerificationToken 的代码,以便将其传递给我的操作文件,但是我的验证组件中未定义 emailAddressVerificationToken。

验证组件

  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;
          });
      };
    }

【问题讨论】:

    标签: javascript reactjs graphql apollo


    【解决方案1】:

    这个错误是由于componentDidMount中的这一行

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

    componentDidMount 不发送任何参数并且您正在接受参数,因为 values 的值未定义。请参考here

    【讨论】:

    • 嗨,我这样做了,但仍然不确定。 ``` checkVerifyEmail = values => { const { verifyEmail } = this.props; values.emailAddressVerificationToken = this.getVerifiedEmailToken();验证电子邮件(值); }; componentDidMount() { console.log("passed componentDidMount"); this.checkVerifyEmail(); }
    • 这就是我所说的componentDidMount 中的参数将始终未定义。您期望的值是什么
    猜你喜欢
    • 2021-01-03
    • 2016-06-15
    • 2020-08-23
    • 2018-05-22
    • 2022-01-23
    • 1970-01-01
    • 2021-10-07
    • 2018-05-06
    • 2017-10-01
    相关资源
    最近更新 更多