Firebase电子邮件验证不会验证帐户 [英] Firebase email verification doesn't verify account
本文介绍了Firebase电子邮件验证不会验证帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我检查用户是否通过电子邮件验证。但是,无论我发送和确认了多少封电子邮件,验证状态仍然是 false
。我在检查时做错了什么?
I checked if user is verified via email or not. However, no matter how many emails I sent and confirm, the verification status is still false
. Am I doing something wrong while checking it?
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if (auth.currentUser?.isEmailVerified)!{
let mainStoryboard: UIStoryboard = UIStoryboard(name:"Main",bundle:nil)
let NewPostViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "NewPostViewController")
//Send the user to the LoginViewController
self.present(NewPostViewController, animated: true, completion: nil)
}else{
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.currentUser.generalDetails.email).", preferredStyle: .alert)
let alertActionOkay = UIAlertAction(title: "Okay", style: .default) {
(_) in
FIRAuth.auth()?.currentUser?.sendEmailVerification(completion: nil)
}
let alertActionCancel = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertVC.addAction(alertActionOkay)
alertVC.addAction(alertActionCancel)
self.present(alertVC, animated: true, completion: nil)
}
})
推荐答案
一个 NSTimer
,时间间隔将检查用户是否已经过验证,然后在验证完成后终止计时器。
How i implemented this feature was to add a NSTimer
, with time interval which would check if the user has been verified and then terminate the timer when the verification was done.
var verificationTimer : Timer = Timer() // Timer's Global declaration
self.verificationTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LoginViewController.checkIfTheEmailIsVerified) , userInfo: nil, repeats: true)
函数检查您当前的用户状态: -
Function to check your current user state:-
func checkIfTheEmailIsVerified(){
FIRAuth.auth()?.currentUser?.reload(completion: { (err) in
if err == nil{
if FIRAuth.auth()!.currentUser!.isEmailVerified{
let feedVCScene = self.navigationController?.storyboard?.instantiateViewController(withIdentifier: "ViewControllerVC_ID") as! ViewController
self.verificationTimer.invalidate() //Kill the timer
self.navigationController?.pushViewController(feedVCScene, animated: true)
// Segueing to the next view(i prefer the instantiation method).
} else {
print("It aint verified yet")
}
} else {
print(err?.localizedDescription)
}
})
}
这篇关于Firebase电子邮件验证不会验证帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文