Search code examples
firebaseflutterdartfirebase-authenticationreset-password

How to check if a given email is present in firebase auth?


I want to implement a reset password form. For that I need to check whether the text input email that user input in out text field is present in our firebase authentication database or not, so that if it is I can send Reset password mail or else show him a pop-dialog to rectify the email.

I've already applied the email checking part where I check wether the text is Email or not.


Solution

  • Firebase Auth can actually manage that for you. Simply call the sendPasswordResetEmail() method like this:

    _auth.sendPasswordResetEmail(email: email)
            .then((void v) => {
              // password reset email sent successfully
            })
            .catchError((Error error) => {
              // There was an error verifying the email
              // Check the output of error.toString()
              // This is where you may want to show a pop-up dialog
            });
    

    If the email is badly formatted or if the email is not present on the Auth Database, the code will always execute the catchError method.