Handle Firebase Apple Platforms Auth Errors

If the completion callback on Authentication methods receives an NSError argument that is not nil, an error has occurred. To dis to appropriate error-handling logic in your production code, check the error code against common errors and method specific errors listed below.

Some errors can be resolved by particular user actions, for example, FIRAuthErrorCodeUserTokenExpired can be resolved by signing the user in again, and FIRAuthErrorCodeWrongPassword by asking the user to provide the right password.

Except in the case of FIRAuthErrorCodeNetworkError or FIRAuthErrorCodeTooManyRequests, retrying a failing operation with the same arguments will never succeed. Make no assumption on whether or not the operation has taken effect on the server side.

When investigating or logging errors, review the userInfo dictionary. FIRAuthErrorNameKey contains a cross-platform error name string that can be used for identifying the error. NSLocalizedDescriptionKey contains a description of the error. This description is meant for the developer, not the user. NSUnderlyingErrorKey contains the underlying error that caused the error in question, if an underlying error is present.

In addition to the main fields listed above, there can be other fields in the userInfo dictionary that you may find useful when diagnosing errors.

Error codes common to all API methods

CodeMeaning
FIRAuthErrorCodeNetworkErrorIndicates a network error occurred during the operation.
FIRAuthErrorCodeUserNotFoundIndicates the user account was not found. This could happen if the user account has been deleted.
FIRAuthErrorCodeUserTokenExpiredIndicates the current user’s token has expired, for example, the user may have changed account password on another device. You must prompt the user to sign in again on this device.
FIRAuthErrorCodeTooManyRequestsIndicates that the request has been blocked after an abnormal number of requests have been made from the caller device to the Firebase Authentication servers. Retry again after some time.
FIRAuthErrorCodeInvalidAPIKeyIndicates the application has been configured with an invalid API key.
FIRAuthErrorCodeAppNotAuthorizedIndicates the App is not authorized to use Firebase Authentication with the provided API Key. go to the Google API Console and check under the credentials tab that the API key you are using has your application’s bundle ID whitelisted.
FIRAuthErrorCodeKeychainErrorIndicates an error occurred when accessing the keychain. The NSLocalizedFailureReasonErrorKey and NSUnderlyingErrorKey fields in the NSError.userInfo dictionary will contain more information about the error encountered.
FIRAuthErrorCodeInternalErrorIndicates an internal error occurred. Please report the error with the entire NSError object.

Method specific error codes

FIRAuth

fetchProvidersForEmail:completion:

CodeMeaning
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed.

signInWithEmail:password:completion:

CodeMeaning
FIRAuthErrorCodeOperationNotAllowedIndicates that email and password accounts are not enabled. Enable them in the Auth section of the Firebase console.
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed.
FIRAuthErrorCodeUserDisabledIndicates the user's account is disabled.
FIRAuthErrorCodeWrongPasswordIndicates the user attempted sign in with a wrong password.

signInWithCredential:completion:

CodeMeaning
FIRAuthErrorCodeInvalidCredentialIndicates the supplied credential is invalid. This could happen if it has expired or it is malformed.
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed, if credential is of the type EmailPasswordAuthCredential.
FIRAuthErrorCodeOperationNotAllowedIndicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console.
FIRAuthErrorCodeEmailAlreadyInUseIndicates the email asserted by the credential (e.g. the email in a Facebook access token) is already in use by an existing account, that cannot be authenticated with this sign-in method. Call fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of the sign-in providers returned. This error will only be thrown if the "One account per email address" setting is enabled in the Firebase console, under Authentication settings.
FIRAuthErrorCodeUserDisabledIndicates the user's account is disabled.
FIRAuthErrorCodeWrongPasswordIndicates the user attempted sign in with a wrong password, if credential is of the type EmailPasswordAuthCredential.

signInAnonymouslyWithCompletion:

CodeMeaning
FIRAuthErrorCodeOperationNotAllowedIndicates that anonymous accounts are not enabled. Enable them in the Auth section of the Firebase console.

signInWithCustomToken:completion:

CodeMeaning
FIRAuthErrorCodeInvalidCustomTokenIndicates a validation error with the custom token.
FIRAuthErrorCodeCustomTokenMismatchIndicates the service account and the API key belong to different projects.

createUserWithEmail:password:completion:

CodeMeaning
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed.
FIRAuthErrorCodeEmailAlreadyInUseIndicates the email used to attempt sign up already exists. Call fetchProvidersForEmail to check which sign-in mechanisms such user used, and prompt the user to sign in with one of those.
FIRAuthErrorCodeOperationNotAllowedIndicates that email and password accounts are not enabled. Enable them in the Authentication section of the Firebase console.
FIRAuthErrorCodeWeakPasswordIndicates an attempt to set a password that is considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo dictionary object will contain more detailed explanation that can be shown to the user.

signOut:

CodeMeaning
FIRAuthErrorCodeKeychainErrorIndicated an error occurred when accessing the keychain. The NSLocalizedFailureReasonErrorKey and NSUnderlyingErrorKey fields in the NSError.userInfo dictionary will contain more information about the error encountered.

FIRUser

Common errors for FIRUser operations

CodeMeaning
FIRAuthErrorCodeInvalidUserTokenIndicates that the signed-in user's refresh token, that holds session information, is invalid. You must prompt the user to sign in again on this device.
FIRAuthErrorCodeUserDisabledIndicates the user's account is disabled and can no longer be used until enabled again from within the Users panel in the Firebase console.

reauthenticateWithCredential:completion:

CodeMeaning
FIRAuthErrorCodeInvalidCredentialIndicates the supplied credential is invalid. This could happen if it has expired or it is malformed.
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed, if credential is of the type EmailPasswordAuthCredential.
FIRAuthErrorCodeWrongPasswordIndicates the user attempted reauthentication with an incorrect password, if credential is of the type EmailPasswordAuthCredential.
FIRAuthErrorCodeUserMismatchIndicates that an attempt was made to reauthenticate with a user which is not the current user.
FIRAuthErrorCodeOperationNotAllowedIndicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console.
FIRAuthErrorCodeEmailAlreadyInUseIndicates the email asserted by the credential (e.g. the email in a Facebook access token) is already in use by an existing account, that cannot be reauthenticated with this sign-in method. Call fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of the sign-in providers returned. This error will only be thrown if the "One account per email address" setting is enabled in the Firebase console, under Authentication settings.
FIRAuthErrorCodeUserDisabledIndicates the user's account is disabled.

updateEmail:completion:

CodeMeaning
FIRAuthErrorCodeEmailAlreadyInUseIndicates the email is already in use by another account.
FIRAuthErrorCodeInvalidEmailIndicates the email address is malformed.
FIRAuthErrorCodeRequiresRecentLoginUpdating a user’s email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

updatePassword:completion:

CodeMeaning
FIRAuthErrorCodeOperationNotAllowedIndicates the administrator disabled sign in with the specified identity provider.
FIRAuthErrorCodeRequiresRecentLoginUpdating a user’s password is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.
FIRAuthErrorCodeWeakPasswordIndicates an attempt to set a password that is considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo dictionary object will contain more detailed explanation that can be shown to the user.

linkWithCredential:completion:

CodeMeaning
FIRAuthErrorCodeProviderAlreadyLinkedIndicates an attempt to link a provider of a type already linked to this account.
FIRAuthErrorCodeCredentialAlreadyInUseIndicates an attempt to link with a credential that has already been linked with a different Firebase account.
FIRAuthErrorCodeOperationNotAllowedIndicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console.

This method may also return error codes associated with updateEmail:completion: and updatePassword:completion: on FIRUser.

unlinkFromProvider:completion:

CodeMeaning
FIRAuthErrorCodeNoSuchProviderIndicates an attempt to unlink a provider that is not linked to the account.
FIRAuthErrorCodeRequiresRecentLoginUpdating email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

sendEmailVerificationWithCompletion:

CodeMeaning
FIRAuthErrorCodeUserNotFoundIndicates the user account was not found.

deleteWithCompletion:

CodeMeaning
FIRAuthErrorCodeRequiresRecentLoginDeleting a user account is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.