问题
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