Firebase身份验证错误处理

时间:2016-09-22 17:04:29

标签: ios firebase error-handling firebase-authentication swift3

不确定这是否已经存在,但我找不到,所以我做到了。希望这能为某人提供帮助。您必须遵循的步骤:

步骤#1 在您尝试登录

后放置警卫声明

第2步调用fireErrorHandle函数

就是这样,享受!

guard let error = AuthErrorCode(rawValue: (error?._code)!) else {
                    return
}
fireErrorHandle(code: error)

func fireErrorHandle(code: AuthErrorCode) {
    switch code {
    case .invalidCustomToken:
        print("Indicates a validation error with the custom token")
    case .customTokenMismatch:
        print("Indicates the service account and the API key belong to different projects")
    case .invalidCredential:
        print("Indicates the IDP token or requestUri is invalid")
    case .userDisabled:
        print("Indicates the user's account is disabled on the server")
    case .operationNotAllowed:
        print("Indicates the administrator disabled sign in with the specified identity provider")
    case .emailAlreadyInUse:
        print("Indicates the email used to attempt a sign up is already in use.")
    case .invalidEmail:
        print("Indicates the email is invalid")
    case .wrongPassword:
        print("Indicates the user attempted sign in with a wrong password")
    case .tooManyRequests:
        print("Indicates that too many requests were made to a server method")
    case .userNotFound:
        print("Indicates the user account was not found")
    case .accountExistsWithDifferentCredential:
        print("Indicates account linking is required")
    case .requiresRecentLogin:
        print("Indicates the user has attemped to change email or password more than 5 minutes after signing in")
    case .providerAlreadyLinked:
        print("Indicates an attempt to link a provider to which the account is already linked")
    case .noSuchProvider:
        print("Indicates an attempt to unlink a provider that is not linked")
    case .invalidUserToken:
        print("Indicates user's saved auth credential is invalid, the user needs to sign in again")
    case .networkError:
        print("Indicates a network error occurred (such as a timeout, interrupted connection, or unreachable host). These types of errors are often recoverable with a retry. The @cNSUnderlyingError field in the @c NSError.userInfo dictionary will contain the error encountered")
    case .userTokenExpired:
        print("Indicates the saved token has expired, for example, the user may have changed account password on another device. The user needs to sign in again on the device that made this request")
    case .invalidAPIKey:
        print("Indicates an invalid API key was supplied in the request")
    case .userMismatch:
        print("Indicates that an attempt was made to reauthenticate with a user which is not the current user")
    case .credentialAlreadyInUse:
        print("Indicates an attempt to link with a credential that has already been linked with a different Firebase account")
    case .weakPassword:
        print("Indicates an attempt to set a password that is considered too weak")
    case .appNotAuthorized:
        print("Indicates the App is not authorized to use Firebase Authentication with the provided API Key")
    case .keychainError:
        print("Indicates an error occurred while attempting to access the keychain")
    default:
        print("Indicates an internal error occurred")
    }
}

0 个答案:

没有答案