Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase - How to detect/observe when Firebase user verified their email like 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.

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?

like image 583
Paul Cham Avatar asked Jan 09 '17 06:01

Paul Cham


People also ask

How can I get user details from Firebase?

If the user login with a custom "email/password" you don't know anything else about that user (apart from the unique user id). If a user login with Facebook, or with Google sign in, you can get other information like the profile picture url. It is explained here: firebase.google.com/docs/auth/android/… .


1 Answers

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);
like image 74
Paul Cham Avatar answered Sep 19 '22 08:09

Paul Cham