验证后的角度Firebase电子邮件验证为假

问题描述 投票:0回答:1

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

  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']);
    })
  }
angular firebase firebase-authentication
1个回答
1
投票

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

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

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

另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.