使用Firebase注册电子邮件/密码时出现“发生网络错误”错误

Nov*_*ovo 1 javascript oauth firebase firebase-authentication

我正在按照Firebase在其官方文档中指定的电子邮件/密码注册设置进行操作;但是,在继续进行身份验证时,我一直收到“发生网络错误”错误。

验证码:

window.onload = function() {
  const config = {
        apiKey: "",
    authDomain: "",
    databaseURL: "",
    storageBucket: "",
    messagingSenderId: ""
  };
  firebase.initializeApp(config);
  const btnSignUp = document.getElementById('btnSignUp');

  btnSignUp.addEventListener('click', function() {
    const inputEmail = document.getElementById('username-input');
    const inputPassword = document.getElementById('password-input');

    const email = inputEmail.value;
    const password = inputPassword.value;
    firebase.auth().createUserWithEmailAndPassword(email,    password).catch(function(error) {
        console.log(error);
    });
  });
};
Run Code Online (Sandbox Code Playgroud)

控制台错误:

A network error (such as timeout, interrupted connection or unreachable host) has occurred.
Run Code Online (Sandbox Code Playgroud)

Nov*_*ovo 5

全部设置-问题是按钮中的'type'属性未定义,并且默认为提交类型。通过设置type =“ button”,此问题已解决。

  • @KaoriYui如果按钮的类型为Submit且位于表单标签内,则它将触发在表单标签中定义的操作,如果没有任何操作,也会触发刷新。发生这种情况时,对Firebase的身份验证请求将被中断,并引发错误。通过将类型设置为按钮,可以减轻该错误的发生。 (3认同)
  • 我遇到了同样的问题,如何将类型设置为按钮解决此问题? (2认同)