Firebase电子邮件验证无法正常工作,无需验证用户是否能够登录 [英] Firebase email verification not working as expected, without verification the user is able to login

查看:135
本文介绍了Firebase电子邮件验证无法正常工作,无需验证用户是否能够登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Firebase时遇到问题,它的电子邮件验证流程也有问题。我可以创建一个新用户,并提供带有链接的电子邮件,以验证电子邮件地址是否已正确发送。现在,仅出于测试目的,我没有单击链接来验证电子邮件,但是,如果我打开该应用程序,则可以访问并执行任何操作。我不确定我缺少什么或做错了什么。在过去的几天里,我一直坚持这一点。任何帮助是极大的赞赏。

I'm having an issue with Firebase and it's email verification flow. I'm able to create a new user, email with a link to verify email address is delivered with no issues. Now, just for testing purposes I'm not clicking on the link to verify the email, but, if I open the app, I'm able to access and do anything. I'm not sure what I'm missing or what I'm doing wrong. I've been stuck with this for the past couple days. Any help is greatly appreciated.

我的代码

@IBAction func loginBtnTapped(_ sender: Any) {

    SVProgressHUD.show()
    guard let email = emailTxt.text,
        let password = passwordTxt.text else { return }

    Auth.auth().signIn(withEmail: email, password: password) { 
(user, error) in
        if error != nil {
            let alert = UIAlertController(title: "Login Error", 
message:"Incorrect Email and/or Password", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: 
.default) { _ in })
            self.present(alert, animated: true){}
            if let error = error {
                print("error: \(error.localizedDescription)")
            }
           if Auth.auth().currentUser?.isEmailVerified == false {
                let alert = UIAlertController(title: "Unable to 
login", message:"Pending: email verification", preferredStyle: 
.alert)
                alert.addAction(UIAlertAction(title: "OK", style: 
.default) { _ in })
                self.present(alert, animated: true){}
                print("")
            SVProgressHUD.dismiss()
            }
        }
            self.dismiss(animated: true, completion: nil)
            SVProgressHUD.dismiss()
        }
    }

预期结果

除非电子邮件经过验证,否则新创建的用户应该无法登录和打开应用。

Newly created user should not be able to login and open the app unless email is verified.

推荐答案

您需要在Firebase数据库中检查已通过电子邮件验证字段,然后如果BOOL值为TRUE,则将其放入应用程序中。单击电子邮件中的链接后,布尔值将自动变为TRUE。因此,与其像您那样做,不如查询该用户的用户表,并检查布尔值是否已通过验证,如果未通过验证,则不要让他们进入。祝您好运,祝您有美好的一天

you need to check on the firebase databasae for the field that says "is email verified" and then if that BOOL value is TRUE, then let them in the app. the bool value will turn to TRUE automatically after they click the link in their email. so instead of doing it like your'e doing, query the user table for that user and check the boolean value for whether they are verified, if they are not, then don't let them in. good luck and have a fabulous day

这篇关于Firebase电子邮件验证无法正常工作,无需验证用户是否能够登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆