Google Firebase forget password

13,925

To implement a forgot password button, you have to call: firebase.auth().sendPasswordResetEmail('[email protected]')

Check the documentation for more details: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#sendPasswordResetEmail

Share:
13,925
mulu gebreselassie
Author by

mulu gebreselassie

-

Updated on June 07, 2022

Comments

  • mulu gebreselassie
    mulu gebreselassie about 2 years

    How do you implement forget password method in my method. I am creating a HTML project which is due soon. My code:

        function toggleSignIn() {
       if (!firebase.auth().currentUser) {
    // [START createprovider]
    var provider = new firebase.auth.GoogleAuthProvider();
    // [END createprovider]
    // [START addscopes]
    provider.addScope('https://www.googleapis.com/auth/plus.login');
    // [END addscopes]
    // [START signin]
    firebase.auth().signInWithPopup(provider).then(function(result) {
      // This gives you a Google Access Token. You can use it to access the    Google API.
      var token = result.credential.accessToken;
      // The signed-in user info.
      var user = result.user;
      // [START_EXCLUDE]
      document.getElementById('quickstart-oauthtoken').textContent = token;
      // [END_EXCLUDE]
    }).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // The email of the user's account used.
      var email = error.email;
      // The firebase.auth.AuthCredential type that was used.
      var credential = error.credential; 
      // [START_EXCLUDE]
      if (errorCode === 'auth/account-exists-with-different-credential') {
        alert("You have already signed up with a different auth provider for that email.");
        // If you are using multiple auth providers on your app you should handle linking
        // the user's accounts here.
      }
    else if (errorCode === 'auth/auth-domain-config-required') {
    alert("An auth domain configuration is required"); 
      }
      else if (errorCode === 'auth/cancelled-popup-request') {
          alert("Popup Google sign in was canceled");
      }
      else if (errorCode === 'auth/operation-not-allowed') {
          alert("Operation is not allowed");
      }
      else if (errorCode === 'auth/operation-not-supported-in-this-environment')      {
          alert("Operation is not supported in this environment");
      }
      else if (errorCode === 'auth/popup-blocked') {
          alert("Sign in popup got blocked");
      }
      else if (errorCode === 'auth/popup-closed-by-user') {
          alert("Google sign in popup got cancelled");
      }
      else if (errorCode === 'auth/unauthorized-domain') {
          alert("Unauthorized domain");
      }
       else {
        console.error(error);
      }
      // [END_EXCLUDE]
      });
      // [END signin]
      } else {
         // [START signout]
        firebase.auth().signOut();
        // [END signout]
        }
       // [START_EXCLUDE]
      document.getElementById('quickstart-sign-ing').disabled = false;
      // [END_EXCLUDE]
     }
    

    Here is a link to give you guidance: https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password Please can you help me

  • Nomura Nori
    Nomura Nori over 7 years
    Hello. I am implementing forgot password function using firebase auth api. And used sendPasswordResetEmail() function and it work well. But firebase api doc says "To complete the password reset, call firebase.auth.Auth#confirmPasswordReset with the code supplied in the email sent to the user, along with the new password specified by the user." Now I want to know param of confirmPasswordReset () function. confirmPasswordReset (code), here where does code comes from?
  • bojeil
    bojeil over 7 years
    You have to parse that code from the password reset email link. The user will click that page. Also this is relevant if you are hosting your own landing page. You have to modify that in the Firebase Console.
  • Makyen
    Makyen over 5 years
    Based on the blog post you've linked being authored by someone with the same name as your user name, you appear to have linked to your own site/blog. If you do so, you must disclose that it's your site. If you don't disclose that it's your own site, it's considered spam. See: What signifies "Good" self promotion?, self-promotion in the help center, What is the exact definition of "spam" for Stack Overflow?, and What makes something spam.
  • Makyen
    Makyen over 5 years
    I have removed the link you had in this answer and you other answer which went to the blog post you probably wrote. Disclosing that you're linking to your own content is required, or it's considered spam. You have visited Stack Overflow a few times since I left my earlier comment and neither added disclosure nor stated you're not the blog author. My assumption is you've chosen not to add disclosure to your two answers. Disclosure is actually quite easy (e.g. "in my blog post"), so I'm assuming you'd prefer to keep the answers, but they need to not be spam. Thus, I've removed those links.