Ionic 3 Firebase不显示电子邮件已通过验证 [英] Ionic 3 firebase doesn't show that email is verified

查看:72
本文介绍了Ionic 3 Firebase不显示电子邮件已通过验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Firebase开发电子邮件验证期间,我遇到了一个问题.

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.

我有这样的代码:

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

但是,在我确认电子邮件地址并运行procedButtonHandler函数之后,在user.emailVerified字段中,除非刷新页面,否则始终会得到假"结果.

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.

知道用户的电子邮件当前是否经过验证的正确方法是什么?是否有任何方法可以监视"emailVerified"字段的更改并将用户重定向到另一个页面,而无需单击按钮?(尝试在"ionViewWillEnter"函数中执行此操作)

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)

推荐答案

如果通过电子邮件验证链接对用户电子邮件进行了带外验证,则验证后您需要在客户端上执行以下两项操作:

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. 调用 currentUser.reload .这将更新用户的emailVerified属性.
  2. 调用 currentUser.getIdToken(true)强制刷新令牌,或者只是等待令牌刷新并自动获取更改.要更新令牌上的 email_verified 属性,这是必需的.
  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现在允许您在验证电子邮件后返回到应用程序.这是通过Web客户端的示例: https://firebase.google.com/docs/auth/web/通过电子邮件传递状态

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.

这篇关于Ionic 3 Firebase不显示电子邮件已通过验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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