繁体   English   中英

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

[英]Firebase authentication:signInWithEmailAndPassword returns error code auth/network-request-failed

我的Web应用程序正在使用Firebase,并且我正在使用Email / Password作为我的应用程序的登录方法。问题是当我的表单位于<form></form>标记内时,我收到auth / network-request-failed错误。如果我将表格更改为div,效果很好。
我遵循的步骤
步骤1 :已启用的电子邮件/密码登录方法 在此处输入图片说明

步骤2 :添加了虚拟用户 在此处输入图片说明

步骤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>

在问大家之前,我在github上查看了Firebase文档示例,当然还有很多谷歌。

请帮我。

可能是由于身份验证状态引起的。请尝试手动键入您的电子邮件和密码,然后

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM