|
| 1 | +package com.firebase.ui.auth; |
| 2 | + |
| 3 | +import android.support.annotation.RestrictTo; |
| 4 | + |
| 5 | +import com.google.firebase.auth.FirebaseAuthException; |
| 6 | + |
| 7 | +/** |
| 8 | + * List of all possible results of {@link FirebaseAuthException#getErrorCode()} and their meanings. |
| 9 | + * |
| 10 | + * This is a temporary band-aid until we have better documentation and exposure for these |
| 11 | + * error codes in the real Firebase Auth SDK. |
| 12 | + */ |
| 13 | +@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) |
| 14 | +public enum FirebaseAuthError { |
| 15 | + |
| 16 | + ERROR_INVALID_CUSTOM_TOKEN("The custom token format is incorrect. Please check the documentation."), |
| 17 | + |
| 18 | + ERROR_CUSTOM_TOKEN_MISMATCH("Invalid configuration. Ensure your app's SHA1 is correct in the Firebase console."), |
| 19 | + |
| 20 | + ERROR_INVALID_CREDENTIAL("The supplied auth credential is malformed or has expired."), |
| 21 | + |
| 22 | + ERROR_INVALID_EMAIL("The email address is badly formatted."), |
| 23 | + |
| 24 | + ERROR_WRONG_PASSWORD("The password is invalid or the user does not have a password."), |
| 25 | + |
| 26 | + ERROR_USER_MISMATCH("The supplied credentials do not correspond to the previously signed in user."), |
| 27 | + |
| 28 | + ERROR_REQUIRES_RECENT_LOGIN("This operation is sensitive and requires recent authentication. Log in again before retrying this request."), |
| 29 | + |
| 30 | + 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."), |
| 31 | + |
| 32 | + ERROR_EMAIL_ALREADY_IN_USE("The email address is already in use by another account."), |
| 33 | + |
| 34 | + ERROR_CREDENTIAL_ALREADY_IN_USE("This credential is already associated with a different user account."), |
| 35 | + |
| 36 | + ERROR_USER_DISABLED( "The user account has been disabled by an administrator."), |
| 37 | + |
| 38 | + ERROR_USER_TOKEN_EXPIRED("The user's credential has expired. The user must sign in again."), |
| 39 | + |
| 40 | + ERROR_USER_NOT_FOUND("There is no user record corresponding to this identifier. The user may have been deleted."), |
| 41 | + |
| 42 | + ERROR_INVALID_USER_TOKEN("The user's credential is no longer valid. The user must sign in again."), |
| 43 | + |
| 44 | + ERROR_OPERATION_NOT_ALLOWED("This operation is not allowed. Enable the sign-in method in the Authentication tab of the Firebase console"), |
| 45 | + |
| 46 | + ERROR_TOO_MANY_REQUESTS("We have blocked all requests from this device due to unusual activity. Try again later."), |
| 47 | + |
| 48 | + ERROR_WEAK_PASSWORD("The given password is too weak, please choose a stronger password."), |
| 49 | + |
| 50 | + ERROR_EXPIRED_ACTION_CODE("The out of band code has expired."), |
| 51 | + |
| 52 | + ERROR_INVALID_ACTION_CODE("The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used."), |
| 53 | + |
| 54 | + ERROR_INVALID_MESSAGE_PAYLOAD("The email template corresponding to this action contains invalid characters in its message. Please fix by going to the Auth email templates section in the Firebase Console."), |
| 55 | + |
| 56 | + ERROR_INVALID_RECIPIENT_EMAIL("The email corresponding to this action failed to send as the provided recipient email address is invalid."), |
| 57 | + |
| 58 | + ERROR_INVALID_SENDER("The email template corresponding to this action contains an invalid sender email or name. Please fix by going to the Auth email templates section in the Firebase Console."), |
| 59 | + |
| 60 | + ERROR_MISSING_EMAIL("An email address must be provided."), |
| 61 | + |
| 62 | + ERROR_MISSING_PASSWORD("A password must be provided."), |
| 63 | + |
| 64 | + ERROR_MISSING_PHONE_NUMBER("To send verification codes, provide a phone number for the recipient."), |
| 65 | + |
| 66 | + ERROR_INVALID_PHONE_NUMBER("The format of the phone number provided is incorrect. Please enter the phone number in a format that can be parsed into E.164 format. E.164 phone numbers are written in the format [+][country code][subscriber number including area code]."), |
| 67 | + |
| 68 | + ERROR_MISSING_VERIFICATION_CODE("The phone auth credential was created with an empty sms verification code"), |
| 69 | + |
| 70 | + ERROR_INVALID_VERIFICATION_CODE("The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user."), |
| 71 | + |
| 72 | + ERROR_MISSING_VERIFICATION_ID("The phone auth credential was created with an empty verification ID"), |
| 73 | + |
| 74 | + ERROR_INVALID_VERIFICATION_ID("The verification ID used to create the phone auth credential is invalid."), |
| 75 | + |
| 76 | + ERROR_RETRY_PHONE_AUTH("An error occurred during authentication using the PhoneAuthCredential. Please retry authentication."), |
| 77 | + |
| 78 | + ERROR_SESSION_EXPIRED("The sms code has expired. Please re-send the verification code to try again."), |
| 79 | + |
| 80 | + ERROR_QUOTA_EXCEEDED("The sms quota for this project has been exceeded."), |
| 81 | + |
| 82 | + ERROR_APP_NOT_AUTHORIZED("This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console."), |
| 83 | + |
| 84 | + ERROR_API_NOT_AVAILABLE("The API that you are calling is not available on devices without Google Play Services."), |
| 85 | + |
| 86 | + ERROR_UNKNOWN("An unknown error occurred."); |
| 87 | + |
| 88 | + /** |
| 89 | + * Get an {@link FirebaseAuthError} from an exception, returning {@link #ERROR_UNKNOWN} as |
| 90 | + * a default. |
| 91 | + */ |
| 92 | + public static FirebaseAuthError fromException(FirebaseAuthException ex) { |
| 93 | + try { |
| 94 | + return FirebaseAuthError.valueOf(ex.getErrorCode()); |
| 95 | + } catch (IllegalArgumentException e) { |
| 96 | + return FirebaseAuthError.ERROR_UNKNOWN; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + private final String description; |
| 101 | + |
| 102 | + FirebaseAuthError(String description) { |
| 103 | + this.description = description; |
| 104 | + } |
| 105 | + |
| 106 | + public String getDescription() { |
| 107 | + return description; |
| 108 | + } |
| 109 | +} |
0 commit comments