Google登录后使用未经证实的Gmail帐户进行Firebase iOS身份验证

时间:2017-08-26 21:32:17

标签: ios swift firebase firebase-authentication google-signin

方案

  1. 用户创建了gmail.com电子邮件帐户,但未对其进行确认。
  2. 用户使用Google登录按钮登录。由于电子邮件尚未确认,Firebase会将其电子邮件帐户替换为Google登录帐户。
  3. 用户尝试使用Gmail电子邮件帐户登录。
  4. 问题 我应该抓到什么错误告诉用户电子邮件已经是另一种身份验证方法的用户?

    代码

    func signIn(with email: String, and password: String) {
        let credential = EmailAuthProvider.credential(withEmail: email, password: password)
        Auth.auth().signIn(with: credential) { (user, error) in
            if let error = error {
                print(error.localizedDescription)
                self.delegate.hideActivityIndicatorView()
                if let errorCode = AuthErrorCode(rawValue: error._code) {
                    switch errorCode {
                    case .accountExistsWithDifferentCredential, .credentialAlreadyInUse:
                        self.delegate.presentAlert(title: "An account with this email already exists", message: nil)
                    case .userNotFound, .wrongPassword, .invalidEmail:
                        self.delegate.presentAlert(title: "Unable to Sign In", message: "Either email or password is incorrect.")
                    default:
                        self.delegate.presentAlert(title: "Something went wrong, please try again later.", message: nil)
                        return
                    }
                }
            }
            print("Successful Email Sign In.")
            self.delegate.hideActivityIndicatorView()
        }
    }
    

0 个答案:

没有答案