我正在使用电子邮件和密码设置授权功能。一切正常,但当我创建新用户时,应用程序会发送一封带有验证链接的电子邮件。验证电子邮件地址后,我想登录,以便返回登录表单。 emial_verified 保持在“假”状态,在我硬重新加载页面后,这是“真”,但当我从验证页面返回登录页面时则不是。有人能帮我吗?
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']);
})
}
这不是错误,而是预期的行为。
电子邮件验证发生在带外(例如:您单击电子邮件客户端中的链接,而不是应用程序中的链接),因此应用程序不知道验证状态已更改。这意味着它无法自动刷新客户端中的 ID 令牌(客户端获取配置文件信息的来源)。
令牌每小时自动刷新,因此最终会更新。如果您想更快地获取更新后的值,可以强制刷新令牌。
另请参阅:
- Firebase 电子邮件验证未更新状态 https://stackoverflow.com/q/48530554
- 我刚才在这里给出的答案:Firebase自定义声明如何设置? https://stackoverflow.com/q/54594100
- Firebase firestore 不更新电子邮件验证状态 https://stackoverflow.com/questions/50894869/firebase-firestore-not-updating-email-verification-status
- Firebase 电子邮件验证未验证帐户 https://stackoverflow.com/questions/40035854/firebase-email-verification-doesnt-verify-account
- 单击电子邮件验证链接 firebase 后 user.emailVerified 不会更改 https://stackoverflow.com/questions/37900447/user-emailverified-doesnt-change-after-clicking-email-verification-link-firebas
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)