Firebase登录密码错误

时间:2018-08-15 17:19:30

标签: javascript html firebase firebase-authentication

我需要帮助,但是我仍然遇到错误,即使我正确输入密码,每次登录时都会说错密码,注册该帐户可以自动登录,但是当我注销该帐户后,刷新然后登录并不断输入错误的密码,有人可以帮助我吗?

function loginbtn(){
 //[then signs in the new user]
 var loginEmail = document.getElementById('txtEmail').value;
 var loginPass = document.getElementById('txtPass').value;
 if (loginEmail.lenght <= 0){
 alert('Please enter an email address.');
}
if (loginPass.lenght <= 0){
alert('Please enter a password.');
} 

// Sign in with email and pass.
firebase.auth().signInWithEmailAndPassword(loginEmail, loginPass).catch(function(error){
 // Handle Errors here.
 var errorCode = error.code;
 var errorMsg = error.message;
 // [START_EXCLUDE]
 if (errorCode ==='auth/wrong-password'){
  alert('Wrong password.');
 } else {
  alert(errorMsg);
 }
 console.log(error);
 document.getElementById('btnLogin').disabled = false;
});
// [END authwithemail]
//disables the button after logging in
document.getElementById('btnLogin').disabled = true;  
}

1 个答案:

答案 0 :(得分:0)

这是正确登录的正确方法:

firebase.auth().signInWithEmailAndPassword(loginEmail , loginPass)
   .then(function(firebaseUser) {
       // Success 
   })
  .catch(function(error) {
       // Error Handling
  });
相关问题