【发布时间】: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