Lov*_*ovs 5 javascript firebase firebase-authentication
我整天都在尝试解决该问题,但无法解决。我很生气,firebase文档太乱了,太疯狂了。
所以我试图在我的React应用程序上实现电子邮件验证。我与文档无关,Google确实发送了电子邮件,我可以单击它,一切都很好。但是,通过电子邮件验证的状态根本没有改变,相信我已经经历了所有stackoverflow主题。
firebase.auth().doSignInWithEmailAndPassword(email, password)
.then(() => {
console.log(firebase.auth().currentUser);
firebase.auth().currentUser.reload()
.then(() => {
console.log(firebase.auth().currentUser);
})
})
Run Code Online (Sandbox Code Playgroud)
因此,我发现我需要重新加载用户才能看到所做的更改,无论他们做什么我都无法使用。这两个控制台日志email.verified = false都始终返回。我绝望,任何人对如何使这项工作有任何想法?我想知道是否将自定义域设置为验证链接是否与此有关?我正在localhost上进行测试,链接链接到实时网站。请帮忙 :(
小智 7
您应该调用的方法是signInWithEmailAndPassword,因此删除函数调用中的“do”:
firebase.auth().signInWithEmailAndPassword(email, password)
.then((credential) => {
const currentUser = credential.user;
console.log(firebase.auth().currentUser);
firebase.auth().currentUser.reload()
.then(() => {
console.log(firebase.auth().currentUser);
})
}).catch((err) => {console.error("Problem with sign in ", err);}
Run Code Online (Sandbox Code Playgroud)
使用credential此函数返回的值并将其user值分配给以currentUser验证用户是否已通过身份验证。
catch最后,记住每次使用时都要在末尾添加then. 在这种情况下,err将包含一个属性err.code来告诉您用户无法通过身份验证的原因。
| 归档时间: |
|
| 查看次数: |
1119 次 |
| 最近记录: |