Firebase电子邮件身份验证网络请求失败

时间:2016-07-28 19:03:42

标签: javascript html firebase-authentication

我正在尝试使用Firebase进行电子邮件身份验证。我一切正常,但今天当我尝试创建一个新用户时,我不断收到错误auth / network-request-failed。我已将代码简化为基础知识,但我仍然遇到此错误。如何避免这种情况并重新启动电子邮件身份验证?

我的代码如下。

     <form id="register-form">
        <input id="register-email" type="text"></input>
        <input id="register-password" type="password"></input>
        <input type="submit" value="Submit"/>
      </form>



$('#register-form').on('submit', function(event) {
  firebase.auth().createUserWithEmailAndPassword($('#register-email').val(), $('#register-password').val()).catch(function(error) {
    console.log(error.code);
  });
});

1 个答案:

答案 0 :(得分:1)

一个Plunker应该更好地了解您当前的代码发生了什么,但不要惊慌,有一个关于如何在Web上开始使用Firebase Auth的Firecast,你可以在这里观看https://www.youtube.com/watch?v=-OKrloDzGpU

为了加速所有事情你可以跟进下面的代码并相应地改变你的项目(也使用jQuery)。

在那里玩得开心!

(function() {
  const config = {
    apiKey: "apiKey",
    authDomain: "authDomain",
    databaseURL: "databaseURL",
    storageBucket: "storageBucket",
  };
  firebase.initializeApp(config);

  const inputEmail = document.getElementById('email');
  const inputPassword = document.getElementById('password');
  const btnSignUp = document.getElementById('btnSignUp');

  btnSignUp.addEventListener('click', e => {
    const email = inputEmail.value;
    const pass = inputPassword.value;
    const auth = firebase.auth();

    const promise = auth.createUserWithEmailAndPassword(email, pass);
    promise.catch(e => console.log(e.message));
  });

  firebase.auth().onAuthStateChanged(firebaseUser => {
    if(firebaseUser) {
      console.log(firebaseUser);
    } else {
      console.log('not logged in');
    }
  });
}());
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Firebase: Register an user</title>
</head>
<body>
  <div class="container">
    <input type="email" id="email" placeholder="Email">
    <input type="password" id="password" placeholder="Password">
    <button id="btnSignUp" class="btn btn-secondary">Signup</button>
  </div>

  <script src="https://www.gstatic.com/firebasejs/3.2.1/firebase.js"></script>
</body>
</html>