Auth.auth().currentUser?.reload() doesn't refresh currentUser.isEmailVerified

送分小仙女□ 提交于 2019-12-24 00:58:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!