点击邮件验证链接firebase后,user.emailVerified不会更改 [英] user.emailVerified doesn't change after clicking email verification link firebase
问题描述
使用下面的代码片段:
验证$ onAuthStateChanged(firebaseUser){
if(firebaseUser){
console.log(firebaseUser); $ b $ if(firebaseUser.emailVerified){
// console.log(firebaseUser。 emailVerified);
toastr.success('Email verified');
} else {
toastr.info('Do verify email');
}
}
$)
console.log(firebaseUser.emailVerified)
返回false,总是,虽然发送验证已启动,收到电子邮件,并点击。
用电子邮件登录后,我检查看如果用户被验证,如果没有,应该发送电子邮件:
验证$ signInWithEma如果(!firebaseUser.emailVerified){
firebaseUser.sendEmailVerification()函数(函数(firebaseUser){
)
console.log('发送电子邮件验证');
}
$ state.go('home');
$ b $ https://console.firebase .google.com / project / my-app-name / authentication / emails
,所有内容都是默认的,带有一个验证链接:
点击此链接验证您的电子邮件地址。
https://my-app-name.firebaseapp.com/__/auth/handler?mode=<action> ;&oobCode=<code>
用于注册的电子邮件会收到验证电子邮件,但单击链接并不会将 user.emailVerified
更改为真正。
是否所有步骤都提供此处,或者还有另外一个步骤没有在文档中找到?
解决方案
正如@Tope所评论的,您需要做一个firebaseUser.reload()以便更新firebaseUser的身份验证状态。
After learning sending email verification is possible in latest firebase, although the docs are missing that, I wanted to test it for myself.
Using the snippet below:
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');
}
}
})
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');
})
Under my https://console.firebase.google.com/project/my-app-name/authentication/emails
, everything is by default, with a verify link as:
Follow this link to verify your email address.
https://my-app-name.firebaseapp.com/__/auth/handler?mode=<action>&oobCode=<code>
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?
解决方案 As commented by @Tope, 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屋!