firebase - Firebase:实时观察电子邮件验证状态
问题描述
如果用户验证了他的电子邮件,我将如何实时检查?
我的流程是这样的:
- 用户注册
- 电子邮件已发送
- 用户看到“请验证您的电子邮件”通知
现在我想:
- setInterval -> 检查电子邮件是否经过验证
- 如果验证显示“电子邮件验证”通知
为此,我需要一种从 firebase 获取用户数据的方法。通常您只需使用 onAuthStateChanged 回调来获取用户数据,但我需要显式获取当前数据。
我该怎么做?
解决方案
找到方法了!
firebase.auth().currentUser.reload()
将获取当前用户数据。所以我所要做的就是:
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)
推荐阅读
- .net - 实体框架核心和一对一关系:重复条目
- android - 使用 Android Studio 签署 APK 时出错 - “任务 ':app:mergeReleaseResources' 的执行失败。”
- python - 求解前一个时间步的 ODE 函数(延迟微分方程)
- python - 使用 pandas 合并和可视化数据集
- java - 伪造 mod 块纹理 1.12
- java - Java2D:如何以正确的旋转围绕中心放置图像
- vba - 根据 Active Combo Box 中的选择生成图表
- git - 如何从终端的桌面上删除 git 跟踪?
- android - 尝试在空对象引用上调用虚拟方法“java.lang.String”
- spring-annotations - 通过代码进行 Spring 配置与通过注释进行配置