Firebase:实时观察电子邮件验证状态 [英] Firebase: Observe email verification status in real time
本文介绍了Firebase:实时观察电子邮件验证状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户验证了他的电子邮件,我将如何实时检查?
How would I be able to check in real time if the user verified his email?
我的流程是这样的:
- 用户注册
- 电子邮件已发送
- 用户看到请验证您的电子邮件"通知
现在我想:
- setInterval->检查电子邮件是否已验证
- 如果已验证,则显示电子邮件已验证"通知
为此,我需要一个从Firebase提取用户数据的方法. 通常,您只使用onAuthStateChanged回调获取用户数据,但我需要显式获取当前数据.
For this I would need a method that fetches the user data from firebase. Usually you just use the onAuthStateChanged callback to get userdata but I need to explicitly fetch current data.
我该怎么做?
推荐答案
找到了方法!
firebase.auth().currentUser.reload()
将获取当前用户数据.所以我要做的就是这个:
will fetch current user data. So all I have to do is this:
this.checkForVerifiedInterval = setInterval(() => {
firebase.auth()
.currentUser
.reload()
.then(ok => {
if (firebase.auth().currentUser.emailVerified) {
this.props.history.push("/verification-email-verified")
window.Materialize.toast("Email verified.", 3000)
clearInterval(this.checkForVerifiedInterval)
}
})
}, 1000)
这篇关于Firebase:实时观察电子邮件验证状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文