未验证的设备上的电子邮件(Firebase)

时间:2019-03-23 19:31:05

标签: ios swift firebase firebase-authentication

我正在尝试注册用户并验证其电子邮件。我已经完成并在电子邮件上但在Auth.auth()。currentUser.isEmailVerified

上对其进行了验证
    if (Auth.auth().currentUser?.isEmailVerified)! {
        // present another vc
    } else {
        print("not verified yet") //Always prints that
    }

这是我的sendVerificationEmail函数:

if let user = Auth.auth().currentUser {
            user.sendEmailVerification(completion: { (error) in
            if let error = error {
                debugPrint(error)
                return
            }
                print("Sent VerificationMail")
        })
    } else {
        print("no user logged in")
    }

在这里我注册用户:

func registrateUser(email: String, password: String, completion: @escaping (Bool) -> Void) {
    Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
        if let error = error {
            debugPrint(error)
            completion(false)
            return
        }
        result?.user.sendEmailVerification(completion: { (error) in
            if let error = error {
                debugPrint(error)
                completion(false)
                return
            }
            completion(true)
        })
    }
}

1 个答案:

答案 0 :(得分:1)

您需要先重新加载用户个人资料,然后再检查电子邮件是否已验证。

使用以下代码:

y_range=(miny,maxy)
相关问题