"app.js“(保存所有的Firebase身份验证和初始化)和"sign-up.html”(一个简单的表单)
但是,我没有收到任何错误,也没有任何东西被发送到控制台,告诉我尽管使用了以下命令,但我已经登录了:
const promise = auth.signInWithEmailAndPassword(email, pass);
promise.catch(e => console.log(e.message));这是app.js:https://www.dropbox.com/s/4ph5e1ejr6ue1d7/app.js?dl=0和https://www.dropbox.com/s/wnvn17ggxn0uckh/sign-up.html?dl=0
发布于 2017-12-10 05:56:10
对从signInWithEmailAndPassword()返回的promise使用then()方法,以了解注册何时成功。由于API会告诉您发生了什么,因此不需要期望SDK在控制台上打印一些内容。你可以自己记录一些东西。
auth.signInWithEmailAndPassword(email, pass).then(user => {
// authenticated user is available here
}).catch(error => {
// something failed
})发布于 2017-12-10 08:07:24
Doug的方法是可行的,但我个人更喜欢use a listener to handle the sign-in/sign-out events
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log("User signed in", user);
} else {
console.log("No user signed in");
}
});这将在您调用signInWithEmailAndPassword()时处理,但(与Doug展示的then()方法不同)它也会在您重新加载页面时触发。
https://stackoverflow.com/questions/47733306
复制相似问题