简体   繁体   中英

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?

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.

With the code in RyanY's answer you can update the password of the current user.

If you want to change the password of another user, you will need to use the Admin SDK in a trusted environment, such as your development machine, a server you control, or Cloud Functions/Cloud Run. With that SDK, you can update any properties of any user (including their password) by their UID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM