0

我嘗試使用github上的quickstart-js將電子郵件和密碼實現Firebase身份驗證:https://github.com/firebase/quickstart-js轉換爲我自己的JavaScript。但是爲什麼我的代碼不顯示任何錯誤,例如用戶使用同一封電子郵件註冊時?未出現firebase auth網絡錯誤?

btnreg.addEventListener('click', e =>{ 
 
       var email = document.getElementById('txtemail').value; 
 
       var password = document.getElementById('txtpass').value; 
 
       if (email.length < 4) { 
 
        alert('Please enter an email address.'); 
 
        return; 
 
       } 
 
       if (password.length < 4) { 
 
        alert('Please enter a password.'); 
 
        return; 
 
       } 
 
       firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { 
 
        var errorCode = error.code; 
 
        var errorMessage = error.message; 
 
        if (errorCode == 'auth/weak-password') { 
 
         alert('The password is too weak.'); 
 
    
 
        } else { 
 
         alert(errorMessage); 
 
         console.log(errorMessage); 
 
        } 
 
        console.log(error); 
 
       }); 
 
      });

+0

你有一個錯誤'console.lo(',而不是'的console.log(' – bojeil

+0

我解決即使我更改爲'console.log(',仍然無法回顧任何錯誤,我也從firebase身份驗證文檔中獲得了此代碼。 –

+0

您是否對repo代碼進行了其他修改?您看到的究竟是什麼?頁面是否重新加載?控制檯中是否有任何錯誤?是網絡請求成功? – bojeil

回答

0

在我的測試使用try {}趕上{}

try { 
     firebase.auth().createUserWithEmailAndPassword(email, password) 
     }catch(error) { 
      console.log(error.code); 
      console.log(error.message); 

     } 
相關問題