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

后端 未结 3 413
渐次进展
渐次进展 2021-02-01 22:54

I use Firebase on Android and Firebase Auth functions.

I try FirebaseAuth.signInWithEmailAndPassword and in case it fails I want to know why the signIn proc

3条回答
  •  春和景丽
    2021-02-01 23:15

    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.

提交回复
热议问题