What is the goal of this task?
- To re-authenticate the user by verifying their current password
(this.state.currentPassword)
- To update the user's password with a new one
(this.state.newPassword)
Which issue am I encountering?
- Successfully completed STEP 1 (re-authentication process)
- Encountering an error during STEP 2 (password update) resulting in an outer try-catch "Error Reauthenticating"
var user = firebaseApp.auth().currentUser;
var credential = firebase.auth.EmailAuthProvider.credential(
firebaseApp.auth().currentUser.email,
this.state.currentPassword
);
// Prompt the user to re-enter their credentials
// STEP 1 : re-authenticate user
user.reauthenticateAndRetrieveDataWithCredential(credential).then(function() {
// User successfully re-authenticated.
// After re-authentication, proceed to update password
//STEP 2 : UPDATE PASSWORD
var newPassword = firebase.getASecureRandomPassword();
user.updatePassword(newPassword).then(function() {
alert("SUCCESS")
// Password updated successfully.
}).catch(function(error) {
console.log(error)
// An error occurred while updating the password.
});
}).catch(function(error) {
// An error occurred during re-authentication.
alert("Error Reauthenticating")
});