Firebase Swift用户身份验证

时间:2015-12-31 03:25:34

标签: swift firebase firebase-authentication

在我的应用中设置登录Firebase时收到以下错误:

  

错误Domain = FirebaseAuthentication Code = -8“(错误代码:INVALID_USER)指定的用户不存在。” UserInfo = {NSLocalizedDescription =(错误代码:INVALID_USER)指定的用户不存在。}   致命错误:在解包可选值时意外发现nil

代码:

@IBAction func loginButtonPressed(sender: UIButton) {
  if let email = emailTextField.text where email != "", let pwd = passwordTextField.text where pwd != "" {
    DataService.ds.BASE_REF.authUser(email, password: pwd, withCompletionBlock: { error, authData in
      if error != nil {
        print (error)
        if error.code == NONEXISTING_USER {
          DataService.ds.BASE_REF.createUser(email, password: pwd, withValueCompletionBlock: { error, result in
            if  error.code == INVALID_EMAIL {
              self.showErrorAlert("Wrong Email", msg: "Sorry wrong email address entered")
              if error.code == -6 {
                self.showErrorAlert("Wrong Password", msg: "Enter a new password")
              }
            } else {
              NSUserDefaults.standardUserDefaults().setValue([KEY_UID], forKey: KEY_UID)
              DataService.ds.BASE_REF.authUser(email, password: pwd, withCompletionBlock: { err, authData in
                self.performSegueWithIdentifier(SEQ_IDEN1, sender: nil)
              })
            }
          })
        }
      }
    })
  } else {
    showErrorAlert("Alert!", msg: "You must enter a Username and Password")
  }
}

func showErrorAlert (title: String, msg: String) {
    let alert = UIAlertController(title: title, message: msg, preferredStyle: .Alert)
    let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
    alert.addAction(action)
    presentViewController(alert, animated: true, completion: nil)
}
}

0 个答案:

没有答案