Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async forgotPassword() {
const { username } = this.state
await Auth.forgotPassword(username)
.then(data => console.log('New code sent', data))
.catch(err => {
if (! err.message) {
console.log('Error while setting up the new password: ', err)
Alert.alert('Error while setting up the new password: ', err)
} else {
console.log('Error while setting up the new password: ', err.message)
Alert.alert('Error while setting up the new password: ', err.message)
}
})
}
// Upon confirmation redirect the user to the Sign In page
send() {
const { authData = {} } = this.props;
const username = this.getUsernameFromInput() || authData.username;
if (!Auth || typeof Auth.forgotPassword !== 'function') {
throw new Error(
'No Auth module found, please ensure @aws-amplify/auth is imported'
);
}
Auth.forgotPassword(username)
.then(data => {
logger.debug(data);
this.setState({ delivery: data.CodeDeliveryDetails });
})
.catch(err => this.error(err));
}
requestCode = async data => {
this.setState({ loading: true });
const { username } = data;
try {
const res = await Auth.forgotPassword(username.toLowerCase());
debug("Forgot password %O", res);
this.setState({ loading: false, codeSent: res.CodeDeliveryDetails, error: null });
} catch (err) {
if (err.code === "LimitExceededException") {
this.setState({
loading: false,
error: `You can't change password that often. Please try later.`
});
return;
}
this.setState({ loading: false, error: err.message });
}
};
return dispatch => {
dispatch(loadingStart());
Auth.forgotPassword(data.email.toLowerCase())
.then(() => dispatch(setAuthPage("forgotPasswordSubmit", "Verification email sent. Please check your email for a code and enter the code below to change your password. If you don't see the email, please check your spam folder.")))
.catch(e => dispatch(onAuthError(e.message)))
.then(() => dispatch(loadingEnd()))
}
}