验证后Angular Firebase电子邮件验证为假 [英] Angular firebase email verification false after verify

查看:80
本文介绍了验证后Angular Firebase电子邮件验证为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用电子邮件和密码设置授权功能.一切正常,但是当我创建一个新用户时,该应用程序会发送一封包含验证链接的电子邮件.验证电子邮件地址后,我想登录,以便回到登录表单. emial_verified始终保持为"false",在我重新加载页面后,此属性为"true",但是当我从验证页面返回登录页面时却没有.有人可以帮我吗?

I'm setting up an authorisation function with e-mail and password. Everything works fine but when i create a new user, the application sends an e-mail with a verification link. After i verify the e-mail adres I want to login so i get back to the login form. the emial_verified keeps staying at 'false', after i hard reload the page this is 'true', but not when i come frome the verification page back to the login page. Can someone help me?

  constructor(
    public afs: AngularFirestore,   // Inject Firestore service
    public afAuth: AngularFireAuth, // Inject Firebase auth service
    public router: Router,  
    public ngZone: NgZone // NgZone service to remove outside scope warning
  ) {   

    /* Saving user data in localstorage when 
    logged in and setting up null when logged out */
    this.afAuth.authState.subscribe(user => {
      if (user) {
        this.userData = user;
        localStorage.setItem('uid', this.userData.uid);
        localStorage.setItem('user', JSON.stringify(this.userData));
        JSON.parse(localStorage.getItem('user'));
      } else {
        localStorage.setItem('user', null);
        JSON.parse(localStorage.getItem('user'));
      }
    })
  }

// Sign up with email/password
  SignUp(email, password) {
    return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
      .then((result) => {
        console.log(result);
        /* Call the SendVerificaitonMail() function when new user sign 
        up and returns promise */
        this.SendVerificationMail();
        this.SetUserData(result.user);
      }).catch((error) => {
        window.alert(error.message)
      })
  }

  // Send email verfificaiton when new user sign up
  SendVerificationMail() {
    return this.afAuth.auth.currentUser.sendEmailVerification()
    .then(() => {
      this.router.navigate(['verify-email-address']);
    })
  }

推荐答案

这不是bug,而是预期的行为.

This is not a bug, but expected behavior.

电子邮件验证是带外进行的(例如:单击电子邮件客户端中而不是应用程序中的链接),因此应用程序不知道验证状态已更改.这意味着它无法自动刷新客户端中的ID令牌(客户端从中获取配置文件信息的位置).

Email verification happens out of band (as in: you click a link in your email client, not in the app), so the app is not aware of the verification status being changed. This means that it can't automatically refresh the ID token, which is where the client gets profile information comes from, in the client.

令牌会每小时刷新一次,因此最终会更新.如果要尽快获取更新的值,可以强制刷新令牌.

The token auto-refreshes every hour, so it will update eventually. If you want to get the updated value sooner, you can force the token to refresh.

另请参阅:

  • Firebase email verification not updating status
  • the answer I just gave here: Firebase custom claim how to set?
  • Firebase firestore not updating email verification status
  • Firebase email verification doesn't verify account
  • user.emailVerified doesn't change after clicking email verification link firebase

这篇关于验证后Angular Firebase电子邮件验证为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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