Firebase on Android: How to check Firebase auth failed reason?

I found some codes inside Firebase library which is similar to the failure messages have seen so far. But havent tried yet. You can give it a try.

    ("ERROR_INVALID_CUSTOM_TOKEN", "The custom token format is incorrect. Please check the documentation."));
    ("ERROR_CUSTOM_TOKEN_MISMATCH", "The custom token corresponds to a different audience."));
    ("ERROR_INVALID_CREDENTIAL", "The supplied auth credential is malformed or has expired."));
    ("ERROR_INVALID_EMAIL", "The email address is badly formatted."));
    ("ERROR_WRONG_PASSWORD", "The password is invalid or the user does not have a password."));
    ("ERROR_USER_MISMATCH", "The supplied credentials do not correspond to the previously signed in user."));
    ("ERROR_REQUIRES_RECENT_LOGIN", "This operation is sensitive and requires recent authentication. Log in again before retrying this request."));
    ("ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL", "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address."));
    ("ERROR_EMAIL_ALREADY_IN_USE", "The email address is already in use by another account."));
    ("ERROR_CREDENTIAL_ALREADY_IN_USE", "This credential is already associated with a different user account."));
    ("ERROR_USER_DISABLED", "The user account has been disabled by an administrator."));
    ("ERROR_USER_TOKEN_EXPIRED", "The user\'s credential is no longer valid. The user must sign in again."));
    ("ERROR_USER_NOT_FOUND", "There is no user record corresponding to this identifier. The user may have been deleted."));
    ("ERROR_INVALID_USER_TOKEN", "The user\'s credential is no longer valid. The user must sign in again."));
    ("ERROR_OPERATION_NOT_ALLOWED", "This operation is not allowed. You must enable this service in the console."));
    ("ERROR_WEAK_PASSWORD", "The given password is invalid."));

I was having the same doubts and I found a bit more information on their documentation.

For example in you are using this method createUserWithEmailAndPassword you can see on their documentation page the following exceptions:

Exceptions:

FirebaseAuthWeakPasswordException thrown if the password is not strong enough FirebaseAuthInvalidCredentialsException thrown if the email address is malformed FirebaseAuthUserCollisionException thrown if there already exists an account with the given email address

For each exception there is also a documentation page, for example the one for FirebaseAuthUserCollisionException

And here you can see the different error types:

ERROR_EMAIL_ALREADY_IN_USE when trying to create a new account with createUserWithEmailAndPassword(String, String) or to change a user's email address, if the email is already in use by a different account

ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL when calling signInWithCredential(AuthCredential) with a credential that asserts an email address in use by another account. This error will only be thrown if the "One account per email address" setting is enabled in the Firebase console (recommended).

ERROR_CREDENTIAL_ALREADY_IN_USE when trying to link a user with an AuthCredential corresponding to another account already in use

So if you do a getErrorCode() and compare the string with any of these Constants you will know exactly the cause of the exception.

Hope it helps.