“网络出现错误”;邮件/密码注册Firebase错误

"A network error has occurred" error on email/password sign up with Firebase

本文关键字:错误 密码 注册 Firebase 邮件 网络      更新时间:2023-09-26

我遵循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);
    });
  });
};

控制台错误:

A network error (such as timeout, interrupted connection or unreachable host) has occurred.

所有设置-问题是按钮中的'type'属性没有定义,默认为提交类型。通过设置type="button",解决了这个问题。