reactjsfirebase-authenticationreset-password

Reactjs firebase reset password without sending reset password email


I am using firebase authentication for my admin website. I know how to reset the password sending the reset password email. I am using that method in my client website. But I want my admin user to reset the password without sending the reset password since they already login. Just like using new password and confirm password form and submit to reset and login again. I don't want my admin user to send the reset password email.

May I know how to reset the firebase authentication without sending the reset password email?


Solution

  • You can use the updatePassword method that comes with firebase.

    import { getAuth, updatePassword } from "firebase/auth";
    
    const auth = getAuth();
    
    const user = auth.currentUser;
    const newPassword = getPWFromForm();
    
    updatePassword(user, newPassword).then(() => {
      // Update successful.
    }).catch((error) => {
      // An error ocurred
      // ...
    });
    

    You would create a textfield where the user enters their new password and then passes it to the updatePassword function.