Firebase email verification doesn't verify account

后端 未结 2 1640
感动是毒
感动是毒 2020-12-18 11:01

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 someth

相关标签:
2条回答
  • 2020-12-18 11:24

    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)
    
            }
        })
    
    }
    
    0 讨论(0)
  • 2020-12-18 11:28

    My way to do it was to add a NSNotification.Name.UIApplicationDidBecomeActive because the user had to leave the app to verify the email:

    NotificationCenter.default.addObserver(self,selector:#selector(APEmailVerificationViewController.checkEmailVerificationState),name:NSNotification.Name.UIApplicationDidBecomeActive, object:  nil)
    

    Do not forget to remove the notification in viewDidDisappear. This is the APEmailVerificationViewController.checkEmailVerificationState func:

    FIRAuth.auth()?.currentUser?.reload(completion: { [unowned self] (error) in
            if error != nil {
                print(error!.localizedDescription)
                return
            }
            if !FIRAuth.auth()!.currentUser!.isEmailVerified {
                return
            }
    
            /**
                Great! We go the playground of the app.
             */
            UIAlertView(title: "Hooray", message: "You've successfully verified your email", delegate: nil, cancelButtonTitle: "Ok").show()
            APIntent.gotoPlayground()
        })
    

    Hope it helps!

    0 讨论(0)
提交回复
热议问题