Skip to content

Instantly share code, notes, and snippets.

@youneshenniwrites
Last active January 19, 2019 13:37
Show Gist options
  • Save youneshenniwrites/7536ecbce301f53479a46fdb0cfde1f0 to your computer and use it in GitHub Desktop.
Save youneshenniwrites/7536ecbce301f53479a46fdb0cfde1f0 to your computer and use it in GitHub Desktop.
forget password methods with AWS Amplify Auth
// 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