如何使用Firebase在iOS上验证用户的电子邮件地址?

如何使用Firebase在iOS上验证用户的电子邮件地址?,第1张

概述我坚持使用firebase进行电子邮件验证.我四处寻找指导但没有帮助.在用户验证他的电子邮件后,我的代码仍然打印出用户尚未验证.我还在尝试习惯firebase的语法.这是我的代码: if FIRAuth.auth()?.currentUser!.emailVerified == true{ FIRAuth.auth()?.signInWithEmail(email.text!, passw 我坚持使用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!,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.",completion: nil)                print("This is a college email and user is created")            }        })    }else{        print("This is not a my.utsa.edu email")        }
解决方法 您在签名之前检查了用户电子邮件是否已经过验证.

这对我有用.

FIRAuth.auth()?.signInWithEmail(txtUsername.text!,password: txtPassword.text!) {        (user,error) in        if let user = FIRAuth.auth()?.currentUser {            if !user.emailVerifIEd{                let alertVC = UIAlertController(Title: "Error",message: "Sorry. Your email address has not yet been verifIEd. Do you want us to send another verification email to \(self.txtUsername.text).",preferredStyle: .Alert)                let alertActionOkay = UIAlertAction(Title: "Okay",style: .Default) {                    (_) in                        user.sendEmailVerificationWithCompletion(nil)                }                let alertActionCancel = UIAlertAction(Title: "Cancel",style: .Default,handler: nil)                alertVC.addAction(alertActionOkay)                alertVC.addAction(alertActionCancel)                self.presentVIEwController(alertVC,completion: nil)            } else {                print ("Email verifIEd. Signing in...")            }        }    }
总结

以上是内存溢出为你收集整理的如何使用Firebase在iOS上验证用户的电子邮件地址?全部内容,希望文章能够帮你解决如何使用Firebase在iOS上验证用户的电子邮件地址?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1100816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存