我正在尝试使用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);
});
});
最佳答案
Plunker应该更好地了解当前代码的运行情况,但不要惊慌,网络上有Firecast关于如何入门Firebase Auth的信息,您可以在此处观看
为了加快一切,您可以按照下面的代码进行操作,并相应地更改您的项目(也使用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>
关于javascript - Firebase电子邮件身份验证网络请求失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38644752/