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

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

问题描述

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

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

推荐答案

这不是错误,而是预期的行为.

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.

另见:

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

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