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);
});
}