Ionic 3 firebase doesn't show that email is verified

↘锁芯ラ 提交于 2021-02-05 11:09:49

问题


I've run into a problem during development of email verification with firebase.

Whenever I try to verify the email address, I can't get the info that user's email address is verified.

I have a code like this:

constructor(private afAuth: AngularFireAuth, public navCtrl: NavController, public navParams: NavParams) {
}

ionViewWillEnter() {
  this.afAuth.auth.onAuthStateChanged(user => {
    if (user && user.emailVerified) {
      this.navCtrl.setRoot(ShoppingListPage);
    }
  });
}

proceedButtonHandler() {
  this.afAuth.auth.onAuthStateChanged(user => {
    if (user && user.emailVerified) {
      this.navCtrl.setRoot(ShoppingListPage);
    }
  });
}

But after I verify the email address and run proceedButtonHandler function, in user.emailVerified field I always get "false" result, unless I refresh the page.

What is the right way to know if user's email is currently verified? And is there any way to watch for "emailVerified" field changes and redirect the user to another page without clicking the button? (there is an attempt to do this in "ionViewWillEnter" function)


回答1:


If the user email is verified out of band via the email verification link, you need to do 2 things on the client after verification:

  1. call currentUser.reload. This will update the emailVerified property on the user.
  2. call currentUser.getIdToken(true) to force token refresh or just wait for the token to be refreshed and automatically pick up the change. This is needed for the email_verified property on the token to update.

Firebase now allows you to return back to the app after email verification. Here is an example via the web client: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions

You can use this when you return back to the app from such operation to reload the user/token knowing the user just verified their email. The above also allows you to pass state in the flow.



来源:https://stackoverflow.com/questions/46268776/ionic-3-firebase-doesnt-show-that-email-is-verified

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