what are the error codes for Flutter Firebase Auth Exception?

Viewed 6232

I have tried to read this thread List of Authorisation errors with Firebase login , and also I have tried to search, but I just can find admin SDK authentication error in here here

those error code from those links are different from the error code for Firebase Auth for Flutter app

I mean, I need the error codes in here

Future<void> signInUsingEmail({required String email, required String password}) async {
    try {
      await _auth.signInWithEmailAndPassword(email: email, password: password);
    } on FirebaseAuthException catch (error) {

      // I need the error.code in here

      print(error.code);
      

    }

could I know all available error codes? so I can write my own error message in my own language. as for now, I can only catch these error codes below

  • "too-many-requests"
  • "wrong-password"
  • "network-request-failed"

what else?

3 Answers

For anyone that doesn't like clicking on links:

signInWithEmailAndPassword

  • wrong-passord: Thrown if the password is invalid for the given email, or the account corresponding to the email does not have a password set.
  • invalid-email: Thrown if the email address is not valid.
  • user-disabled: Thrown if the user corresponding to the given email has been disabled.
  • user-not-found: Thrown if there is no user corresponding to the given email.

createUserWithEmailAndPassword

  • email-already-in-use: Thrown if there already exists an account with the given email address.
  • invalid-email: Thrown if the email address is not valid.
  • operation-not-allowed: Thrown if email/password accounts are not enabled. Enable email/password accounts in the Firebase Console, under the Auth tab.
  • weak-password: Thrown if the password is not strong enough.

signInWithCredential

  • account-exists-with-different-credential: Thrown if there already exists an account with the email address asserted by the credential. Resolve this by calling fetchSignInMethodsForEmail and then asking the user to sign in using one of the returned providers. Once the user is signed in, the original credential can be linked to the user with linkWithCredential.
  • invalid-credential: Thrown if the credential is malformed or has expired.
  • operation-not-allowed: Thrown if the type of account corresponding to the credential is not enabled. Enable the account type in the Firebase Console, under the Auth tab.
  • user-disabled: Thrown if the user corresponding to the given credential has been disabled.
  • user-not-found: Thrown if signing in with a credential from EmailAuthProvider.credential and there is no user corresponding to the given email.
  • wrong-password: Thrown if signing in with a credential from EmailAuthProvider.credential and the password is invalid for the given email, or if the account corresponding to the email does not have a password set.
  • invalid-verification-code: Thrown if the credential is a PhoneAuthProvider.credential and the verification code of the credential is not valid.
  • invalid-verification-id: Thrown if the credential is a PhoneAuthProvider.credential and the verification ID of the credential is not valid.id.

reauthenticateWithCredential

  • user-mismatch: Thrown if the credential given does not correspond to the user.
  • user-not-found: Thrown if the credential given does not correspond to any existing user.
  • invalid-credential: Thrown if the provider's credential is not valid. This can happen if it has already expired when calling link, or if it used invalid token(s). See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.
  • invalid-email: Thrown if the email used in a EmailAuthProvider.credential is invalid.
  • wrong-password: Thrown if the password used in a EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password.
  • invalid-verification-code: Thrown if the credential is a PhoneAuthProvider.credential and the verification code of the credential is not valid.
  • invalid-verification-id: Thrown if the credential is a PhoneAuthProvider.credential and the verification ID of the credential is not valid.

signInWithAuthProvider

  • user-disabled: Thrown if the user corresponding to the given email has been disabled.

signInAnonymously

  • operation-not-allowed: Thrown if anonymous accounts are not enabled. Enable anonymous accounts in the Firebase Console, under the Auth tab.

signInWithEmailLink

  • expired-action-code: Thrown if OTP in email link expires.
  • invalid-email: Thrown if the email address is not valid.
  • user-disabled: Thrown if the user corresponding to the given email has been disabled.

So I created this gist And it's basically a handler for some common firebase auth exceptions.

This is an example on how to use it

Future createUser(String email, String password) async {
    try {
      UserCredential customUserCredential = await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
              email: email, password: password);
      return customUserCredential.user!.uid;
    } on FirebaseAuthException catch (authError) {
      throw CustomAuthException(authError.code, authError.message!);
    } catch (e) {
      throw CustomException(errorMessage: "Unknown Error");
    }
Related