简体   繁体   中英

Do not warn if there is no registered user with Email address in Flutter Firebase Auth Password Reset

I am developing an application with Flutter. I'm having a problem with resetting password in Firebase Auth. If there is no account belonging to the entered e-mail address, it gives an error. I want to show this error to the user with a private message.

I wrote a code like this:

try {
  _auth.sendPasswordResetEmail(email: _emailController.text);
  ShowAlert(
    context,
    "Error",
    "Password reset instructions have been sent to your email address."
  );
} on FirebaseAuthException catch (e) {
  if (e.code == "user-not-found") {
    ShowAlert(
      context,
      "Error",
      "No registered user with e-mail address was found."
    );
  } else {
    ShowAlert(
      context,
      "Error",
      "Unknown error occurred."
    );
  }
}

I wrote code to show custom message to user but unfortunately it is not working. It's getting an error.

Error:

FirebaseAuthException ([firebase_auth/user-not-found] There is no user record corresponding to this identifier. The user may have been deleted.)

Why could this be? How can I solve this problem? Many thanks in advance for your help.

Your are not awaiting for the result of _auth.sendPasswordResetEmail() . Add await before it:

try {
  await _auth.sendPasswordResetEmail(email: _emailController.text);
  ...
}

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