Firebase - How to detect/observe when Firebase user verified their email like onAuthStateChanged

荒凉一梦 提交于 2019-12-06 22:26:08

问题


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.

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?


回答1:


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);



回答2:


It's sad that firebase doesn't address this issue, I ended up holding a emailVerified flag on a firestore doc to sync state between open tabs.



来源:https://stackoverflow.com/questions/41541887/firebase-how-to-detect-observe-when-firebase-user-verified-their-email-like-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!