【问题标题】:firebase auth web error does not appear?没有出现firebase auth web错误?
【发布时间】:2018-01-16 02:09:53
【问题描述】:

我尝试使用来自 github 上的 quickstart-js 的电子邮件和密码实现 Firebase 身份验证:https://github.com/firebase/quickstart-js 到我自己的 javascript 中。但是为什么我的代码没有显示任何错误,比如当用户使用相同的电子邮件注册时?

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

【问题讨论】:

  • 你有一个错误console.lo( 而不是console.log(
  • 即使我改成console.log(,仍然无法找回任何错误,我也从firebase auth docs获得了这段代码。
  • 您是否对 repo 代码进行了其他修改?你到底看到了什么?页面是否重新加载?控制台中是否有任何错误?网络请求成功了吗?
  • 如果我使用来自 repo 的原始代码,如果我尝试使用相同的电子邮件注册,它将显示警告框 The email address is already in use by another account.。但它没有在我的代码中显示警报框。在回购代码中,它有window.onload = function(),但在firebase auth 文档中,这个function 不包括在内。 Firebase 身份验证文档只给我firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error),我在控制台中输入任何错误。我也关注 Firecast 视频:youtu.be/-OKrloDzGpU,仍然没有发生错误。
  • window.onload 需要在加载 dom 后添加所有点击处理程序。你确定你的点击回调在点击时运行吗?您的点击处理程序可能未正确设置。

标签: javascript firebase firebase-authentication firebase-security


【解决方案1】:

在我的测试中,我使用 try{} catch {} 解决了

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

      }

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 2021-06-24
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多