单击电子邮件验证链接 firebase 后,user.emailVerified 不会更改 [英] user.emailVerified doesn't change after clicking email verification link firebase

查看:13
本文介绍了单击电子邮件验证链接 firebase 后,user.emailVerified 不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习发送在最新的firebase中可以进行电子邮件验证后,尽管文档中缺少该内容,但我想对其进行测试为我自己.

After learning sending email verification is possible in latest firebase, although the docs are missing that, I wanted to test it for myself.

使用下面的代码片段:

  Auth.$onAuthStateChanged(function(firebaseUser) {
    if (firebaseUser) {
      console.log(firebaseUser);
      if (firebaseUser.emailVerified) {
        // console.log(firebaseUser.emailVerified); 
        toastr.success('Email verified');
      } else {
        toastr.info('Do verify email');
      }
    }
  })

console.log(firebaseUser.emailVerified) 始终返回 false,尽管已启动发送验证、收到电子邮件并单击.

The console.log(firebaseUser.emailVerified) returns false, always, although a send verification was initiated, email received, and clicked on.

在使用电子邮件登录后,我检查用户是否已通过验证,如果没有,则应发送电子邮件:

Right after login with email, I check to see if user is verified, if not, email should be sent:

Auth.$signInWithEmailAndPassword(email, password)
  .then(function(firebaseUser) {
    if (!firebaseUser.emailVerified) {
      firebaseUser.sendEmailVerification();
      console.log('Email verification sent');
    }
    $state.go('home');
  })

在我的https://console.firebase.google.com/project/my-app-name/authentication/emails下,一切都是默认的,有一个验证链接:

Under my https://console.firebase.google.com/project/my-app-name/authentication/emails, everything is by default, with a verify link as:

点击此链接以验证您的电子邮件地址.https://my-app-name.firebaseapp.com/__/auth/handler?mode=&oobCode=

我用来注册的电子邮件收到了验证电子邮件,但是,单击该链接不会将 user.emailVerified 更改为 true.

The email I use to sign up receives the verify email message, yet, clicking the link does nothing to change the user.emailVerified to true.

步骤概述这里是全部,还是文档中没有找到另一个步骤?

Are the steps outline here all there is, or there's yet another step not found in the docs?

推荐答案

正如 Tope一条评论,你需要做一个firebaseUser.reload() 以便更新对 firebaseUser 的身份验证状态的更改.

As mentioned by Tope in a comment, you need to do a firebaseUser.reload() in order for the change to the firebaseUser's authentication status to be updated.

这篇关于单击电子邮件验证链接 firebase 后,user.emailVerified 不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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