问题
I'm trying to implement email verification with Firebase. I've created Dynamic Links that redirect to my app successfully. I have tested the link on the web too. It works perfectly and it verifies the email. However, the link on the verification email redirects me to my app, Auth.auth().currentUser.isEmailVerified still gives me false, even though I ran Auth.auth().currentUser?.reload() command beforehand.
Any help on this?
回答1:
You can set up a timer like this:
var verificationTimer : Timer = Timer() // Timer's Global declaration
self.verificationTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LoginViewController.checkIfTheEmailIsVerified) , userInfo: nil, repeats: true)
and then repeatedly check user's current state using this function:
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)
}
})
}
Hope this helps :)
Source: https://stackoverflow.com/a/40037547/6596799
来源:https://stackoverflow.com/questions/47126463/auth-auth-currentuser-reload-doesnt-refresh-currentuser-isemailverified