Last active
January 19, 2019 13:37
-
-
Save youneshenniwrites/7536ecbce301f53479a46fdb0cfde1f0 to your computer and use it in GitHub Desktop.
forget password methods with AWS Amplify Auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request a new password | |
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 | |
async forgotPasswordSubmit() { | |
const { username, authCode, newPassword } = this.state | |
await Auth.forgotPasswordSubmit(username, authCode, newPassword) | |
.then(() => { | |
this.props.navigation.navigate('SignIn') | |
console.log('the New password submitted successfully') | |
}) | |
.catch(err => { | |
if (! err.message) { | |
console.log('Error while confirming the new password: ', err) | |
Alert.alert('Error while confirming the new password: ', err) | |
} else { | |
console.log('Error while confirming the new password: ', err.message) | |
Alert.alert('Error while confirming the new password: ', err.message) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment