var user = firebase.auth().currentUser;
var newPassword = getASecureRandomPassword();
user.updatePassword(newPassword).then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
var user = firebase.auth().currentUser;
if (user.password == state.password) {
user.updatePassword(state.password).then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
}
import {
EmailAuthProvider,
getAuth,
reauthenticateWithCredential,
updatePassword,
} from "firebase/auth";
// 1) Reauthenticate credential
reAuthenticateCredential(currentPassword: string, newPassword: string) {
const user = getAuth().currentUser;
const cred = EmailAuthProvider.credential(user.email, currentPassword);
reauthenticateWithCredential(user, cred);
this.changePassword(newPassword);
}
// 2) Then call update password function
changePassword(newPassword: string) {
const user = getAuth().currentUser;
updatePassword(user, newPassword)
.then(() => {
// Update successful.
this.toasterService.notificationSuccess(
message.PASSWORD_IS_UPDATED_SUCCESSFULLY
);
this.logout();
})
.catch((error: any) => {
// An error happened.
this.toasterService.notificationDanger(error.message);
});
}