Firebase-当Firebase用户验证其电子邮件(如onAuthStateChanged)时如何检测/观察 [英] Firebase - How to detect/observe when Firebase user verified their email like onAuthStateChanged

查看:51
本文介绍了Firebase-当Firebase用户验证其电子邮件(如onAuthStateChanged)时如何检测/观察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解要检查用户的电子邮件是否已验证,可以使用

I understand that to check if the user's email is verified, I can use

firebase.auth().onAuthStateChanged((user) => {
    console.log(user["emailVerified"]);
})

但是,我的问题是,每当用户在收件箱中验证其电子邮件地址时,我都希望进行观察/收听并重定向到另一个页面.

However my problem is, I want to observe/listen and redirect to another page whenever the user verified their email address on their inbox.

根据我的测试,onAuthStateChanged在用户登录,更新其个人资料并注销时触发,但在用户验证其收件箱中的电子邮件地址时不触发.

Based on my testing, onAuthStateChanged is triggered when user logged in, updated their profile, and logged out, but is not triggered when the user verified their email address on their inbox.

无论如何,我是否可以检测到用户何时通过验证并自动重定向到另一个页面?

Is there anyway I can detect when the user is verified and automatically redirect to another page?

推荐答案

我设法通过setInterval函数使其工作,该函数每秒使用以下命令检查用户的emailVerified属性:

I managed to make it work through a setInterval function which checks the user's emailVerified property every second with the following:

setInterval(function() {
  firebase.auth().currentUser.reload();
  if (firebase.auth().currentUser.emailVerified) {
      console.log("Email Verified!");
      this.navCtrl.setRoot(HomePage);
  }
}, 1000);

这篇关于Firebase-当Firebase用户验证其电子邮件(如onAuthStateChanged)时如何检测/观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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