Firebase电子邮件认证网络请求失败

问题描述:

我正在尝试使用Firebase进行电子邮件认证。我有一切工作正常,但今天当我尝试创建一个新的用户,我不断收到错误auth /网络请求失败。我简化了我的代码到非常基础,但我继续得到这个错误。我如何避免这种情况,并再次使电子邮件验证工作?Firebase电子邮件认证网络请求失败

我的代码如下。

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

什么环境中,你在运行这个?它是一个网页吗?如果是这样,你是否尝试在不同的设备/网络上运行它? – bojeil

+0

我正在使用Chrome。没有访问不同的网络,但我切换了一些我的代码,以反映华雷斯的风格,似乎这样做。 – Chris

+0

版本信息和足够的代码来重现问题。请参阅[如何提问](http://*.com/help/how-to-ask)和[创建mcve](http://*.com/help/mcve)。 – Kato

一个Plunker应该是更好地看到发生了什么事情与你当前的代码,但不要惊慌,有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>