简体   繁体   中英

Firebase Authentication - Forget/ Reset Password

I am adding the functionality of authentication to my app. I am using firebase REST api for authentication. I am successful in implementing login, logout, signup etc functions. Now I want to implement forget or reset password.

I want to send the api request to firebase to generate the code and receive it at user's email. So that app can send back the code with the new password back to firebase for resetting.

I am not able to find the appropriate api from firebase documentation. Will anyone please advise?

I'm right in the middle of working with password changing with Firebase myself, and though I'm not using Angular, here's the links to the two key methods needed for changing the password, from the FB Auth documentation.

From the docs, to send the email: https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#sendpasswordresetemail

import { getAuth, sendPasswordResetEmail } from "firebase/auth";

const auth = getAuth();
sendPasswordResetEmail(auth, email)
  .then(() => {
    // Password reset email sent!
    // ..
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    // ..
  });

Once the user clicks the link in the email, they will end up on your site's email landing page (defined in the Auth email templates or through your custom third party email solution). The link will have a parameter "oobCode", which is needed to reset the password.

On that landing page, ask the user for a new password, and then pass the oobCode and the new password to the confirmPasswordReset function: https://firebase.google.com/docs/reference/js/v8/firebase.auth.Auth#confirmpasswordreset

import { getAuth, confirmPasswordReset } from "firebase/auth";

const auth = getAuth();
const oobCode = [However Angular reads querystring values]('oobCode');
confirmPasswordReset (auth, oobCode)
  .then(() => {
    // Password has been reset!
    // ..
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    // ..
  });

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