【问题标题】:email/password authentication for firebase SERVER_ERRORfirebase SERVER_ERROR 的电子邮件/密码身份验证
【发布时间】:2013-07-11 21:48:25
【问题描述】:

我正在尝试使用 Firebase 的简单登录并尝试遵循How do I use Firebase Simple Login with email & password 中列出的一般方法。

但是,每次我尝试创建新用户(或登录)时,我都会得到一个

SERVER_ERROR:与 wss://s-xxxxxxxx 的连接在页面加载时中断。

这是怎么引起的,我该如何解决?

此外,当我对值进行硬编码(即,将 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
                  }
                });

【问题讨论】:

    标签: javascript email authentication passwords firebase


    【解决方案1】:

    您看到的问题是登录方法的网络请求失败,因为您在完成之前导航离开当前页面。表单实际上正在提交,因此页面正在重定向/刷新。

    为了防止这种行为,请更新您的代码以在每个 $(element).submit() 方法的底部包含一个 return false;,这将阻止表单提交并且身份验证请求将完成。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-13
      • 2016-10-13
      • 2018-11-11
      • 2021-11-21
      • 2019-08-05
      • 2019-03-15
      • 2016-11-13
      • 1970-01-01
      相关资源
      最近更新 更多