Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Change Password in firebase v9

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);
      });
  }
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Change #Password #firebase
ADD COMMENT
Topic
Name
2+9 =