简体   繁体   English

firebase SERVER_ERROR的电子邮件/密码身份验证

[英]email/password authentication for firebase SERVER_ERROR

I'm trying to use Firebase's simple login and attempting to follow the general methods laid out in How do I use Firebase Simple Login with email & password . 我正在尝试使用Firebase的简单登录,并尝试按照如何使用Firebase简单登录电子邮件和密码中列出的一般方法进行操作

Everytime I try to create a new user (or sign in), however, I get a 然而,每当我尝试创建一个新用户(或登录)时,我都会得到一个

SERVER_ERROR: The connection to wss://s-xxxxxxxx was interrupted while the page was loading. SERVER_ERROR:加载页面时,与wss:// s-xxxxxxxx的连接中断。

How is this caused and how can I solve it? 这是怎么造成的,我该如何解决?

Also, it works on Firefox when I hardcode values (ie take createUser outside of the register submit handler), but not on Chrome. 此外,当我对值进行硬编码时(即在寄存器提交处理程序之外使用createUser),它适用于Firefox,但不适用于Chrome。

login.html

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
    <script type='text/javascript' src='https://cdn.firebase.com/v0/firebase.js'></script>
    <script type='text/javascript' src='https://cdn.firebase.com/v0/firebase-simple-login.js'></script>
    </head>
    <body>
        <div id="login_or_register">
        </div>
        <button id="logout">Logout</button>
        <script type='text/javascript' src='loginScript.js'></script>
    </body>
</html>

loginScript.js

function showLoginRegister(auth){

                    $register_form = $('<form id="register">'+
                      '<input type="text" name="register-email" id="register-email" value="email@example.com">'+
                    '<input type="password" name="register-password" id="register-password" value="password">'+
                    '<input type="submit" value="Create an account!"/>'+'</form>')

                    $login_form = $('<form id="login">'+'<input type="text" name="login-email" id="login-email" value="email@example.com">'+
                    '<input type="password" name="login-password" id="login-password" value="password">'+
                    '<input type="checkbox" name="rememberCheckbox" id="rememberCheckbox" checked>'+
                    '<input type="submit" value="Sign in"/>'+'</form>')
                    $('#login_or_register').append($register_form,$login_form);

                    $("#register").submit(function() {
                        var email = $("#register-email").val();
                    var password = $("#register-password").val();
                    auth.createUser(email, password, function(error, user) {
                            if (!error) {
                                  auth.login("password", {
                                  email: email,
                                    password: password,
                                    rememberMe: false
                                });
                            }
                            else{
                                console.log(error);
                            }
                        });
                    });

                    $("#login").submit(function() {
                        var email = $("#login-email").val();
                    var password = $("#login-password").val();
                    var checkbox = $("#rememberCheckbox").val();
                      auth.login("password", {
                            email: email,
                            password: password,
                            rememberMe: checkbox
                        });
                    });  
                };


                var ref = new Firebase('https://xxx.firebaseio.com/');
                var auth = new FirebaseSimpleLogin(ref, function(error, user) {
                    if (error){
                        console.log(error);
                      return;
                  }
                  if (user) {
                    // user authenticated with Firebase
                        $("#logout").click(function(){
                            auth.logout();
                       })
                  } 
                  else {
                    showLoginRegister(this);
                      // user is logged out
                  }
                });

The problem you're seeing is that the network request for the login methods are failing since you're navigating away from the current page before they can complete. 您看到的问题是登录方法的网络请求失败,因为您在完成之前导航离开当前页面。 The form is actually being submitted, and the page is redirecting / refreshing as a result. 实际上正在提交表单,因此页面将重定向/刷新。

In order to prevent this behavior, update your code to include a return false; 为了防止出现这种情况,请更新代码以包含return false; at the bottom of each of the $(element).submit() methods, which will prevent the form from submitting and the authentication requests will complete. 在每个$(element).submit()方法的底部,这将阻止表单提交,身份验证请求将完成。

$("#el").submit(function() {
  // Do stuff here ...
  return false;
});

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

相关问题 电子版Firebase电子邮件/密码身份验证 - Firebase email/password authentication in electron 使用电子邮件/密码进行Firebase身份验证 - Firebase Authentication using email/password Polymer firebase。通过密码和电子邮件进行身份验证 - Polymer firebase.. Authentication with password and email Firebase无效的电子邮件身份验证错误 - firebase invalid email authentication error 尝试让 Firebase 电子邮件/密码身份验证与 React Native 一起使用 - Trying to get the Firebase Email/Password Authentication to work with React Native Firebase密码和电子邮件身份验证失败,并显示错误 - Firebase password and email authentification fails with error 使用Firebase注册电子邮件/密码时出现“网络错误”错误 - “A network error has occurred” error on email/password sign up with Firebase Firebase Email 链路认证 - Firebase Email Link Authentication Firebase Web 身份验证不起作用 - 仅针对类型错误的 Email 返回错误 - Firebase Web Authentication Not Working - Returning Error Only for Badly typed Email Firebase 数据库用户身份验证:使用来自电话提供商的 UID 创建用户 Email 和密码 - Firebase Database User Authentication: Create User Email and Password with UID from Phone Provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM