Firebase身份验证:signInWithEmailAndPassword返回错误代码auth / network-request-failed

时间:2017-04-05 14:32:07

标签: javascript firebase firebase-authentication

我的网络应用程序正在使用Firebase,而我正在使用电子邮件/密码作为我的应用程序的登录方法。我的表单在<form></form>标签内时我正在获取 auth / network-request-失败错误。如果我将表单更改为div,则身份验证工作正常 我遵循的步骤
第1步:启用电子邮件/密码登录方法 enter image description here

第2步:添加了虚拟用户 enter image description here

第3步:这是我的身份验证功能

function authenticateUser() {
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;

    firebase.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        if (errorCode === 'auth/wrong-password') {
            alert('Wrong password.');
        }
        else if (errorCode = 'auth/network-request-failed') {
            alert('Network error.');
        } else {
            alert(errorMessage);
        }
        console.log(error);
    });
}

第4步:我的登录表单

<form class="form-signin">
                        <h1>Login to Your Account</h1>
                        <label for="inputEmail" class="sr-only">Email address</label>
                        <input type="email" id="email" class="form-control" placeholder="Email address" required="" autofocus="">
                        <label for="inputPassword" class="sr-only">Password</label>
                        <input type="password" id="password" class="form-control" placeholder="Password" required="">
                        <div class="checkbox">
                            <label><input type="checkbox" value="remember-me"> Remember me</label>
                        </div>
                        <button id="login" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
                    </form>

在向人们询问Firebase Documentationsamples on github之前,我们搜索了很多内容。

请帮帮我。

1 个答案:

答案 0 :(得分:0)

可能是由身份验证状态导致尝试手动输入您的电子邮件和密码

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
    var errorCode = error.code;
    var errorMessage = error.message;
    console.error({ ErrorCode: errorCode, ErrorMessage: errorMessage });
});
相关问题