【发布时间】:2016-10-29 21:29:03
【问题描述】:
我无法使用 firebase 进行电子邮件验证。我四处寻找指导,但没有任何帮助。用户验证他的电子邮件后,我的代码仍然打印出用户尚未验证。我仍在尝试习惯 firebase 的语法。这是我的代码:
if FIRAuth.auth()?.currentUser!.emailVerified == true{
FIRAuth.auth()?.signInWithEmail(email.text!, password: passsword.text!, completion: {
user, error in
if error != nil{
print("Email/password is wrong or user does not exist")
}else{
print("Successful login.")
}
})
}else{
print("Please verify your email.")
}
这是我的注册代码:
let eduEmail = email.text
let endInEdu = eduEmail?.hasSuffix("my.utsa.edu")
if endInEdu == true {
FIRAuth.auth()?.createUserWithEmail(email.text!, password: passsword.text!, completion: {
user, error in
if error != nil{
let alert = UIAlertController(title: "User exists.", message: "Please use another email or sign in.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
print("Email has been used, try a different one")
}else{
FIRAuth.auth()?.currentUser!.sendEmailVerificationWithCompletion({ (error) in
})
let alert = UIAlertController(title: "Account Created", message: "Please verify your email by confirming the sent link.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
print("This is a college email and user is created")
}
})
}else{
print("This is not a my.utsa.edu email")
}
【问题讨论】:
-
天哪!欢迎来到stackoverflow。我强烈建议您设置一个更具描述性的问题标题。
-
您是否在 currentUser 上调用 sendEmailVerification,然后单击通过电子邮件发送的电子邮件验证链接?
-
是的,我是。它在我的注册视图控制器文件中。注册后,它会在创建帐户时自动发送电子邮件
-
我编辑了代码。
标签: ios swift firebase firebase-authentication