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); 

     } 
相关问题