Ral*_*thy 5 javascript amazon-web-services reactjs aws-amplify
如何使用 Amplify 返回该特定用户的状态?我this.state.email有为用户。
这是我的 handleSubmit 函数的样子:
handleSubmit = async event => {
event.preventDefault();
this.setState({ isLoading: true });
try {
const newUser = await Auth.signUp({
username: this.state.email,
password: this.state.password,
});
this.setState({ newUser });
} catch (e) {
if (e.name === 'UserNotConfirmedException') {
alert(
'Looks like your account isn\'t confirmed! ' +
'Please check your email to find the confirmation code.',
);
// await Auth.resendSignUp(this.state.email);
this.setState({
newUser: {
username: this.state.email,
password: this.state.password,
},
});
} else if (e.name === 'UsernameExistsException') {
// how to check if unconfirmed?
if ('not sure what to put here') {
alert(
'Looks like your account isn\'t confirmed! ' +
'Please check your email to find the confirmation code.',
);
// bring up confirmation page
} else {
alert(
'Looks like you already have an account! ' +
'Please log in with your current password.',
);
this.props.history.push('/login');
}
} else {
alert(e.message);
}
}
this.setState({ isLoading: false });
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我不完全理解你的问题,但我认为我的解释无论如何都会有所帮助。
当您尝试再次注册用户时,您将收到“UsernameExistsException”。
但是,当您尝试使用该用户登录时,会返回“UserNotConfirmedException”。因此,这需要在登录中处理。
你需要的是这样的东西。
handleSubmit = async event => {
event.preventDefault();
this.setState({ isLoading: true });
try {
const newUser = await Auth.signUp({
username: this.state.email,
password: this.state.password, 'attributes': {
name: this.state.name,
email: this.state.email
}
});
this.setState({
newUser
});
} catch (e) {
if(e.name === 'UsernameExistsException') {
alert("You are already registered. Resending the verification code to " + this.state.email);
await Auth.resendSignUp(this.state.email);
this.state.resent = true;
} else {
alert(e.message);
}
}
this.setState({ isLoading: false });
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1660 次 |
| 最近记录: |