1

我已经尝试了 Firebase Facebook 身份验证的基本步骤。因此,在我的应用中,用户可以使用 Firebase Facebook 身份验证成功登录。但是我在注销时遇到问题。

我使用了注销按钮并在其上绑定点击事件,如下所示:

$(function(){
    $('#lgout').click(function(){   
       auth.logout();
    });
});

对于登录,我使用以下代码:

var chatRef = new Firebase('https://my-firebase-url');
    var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
          if (error) {
            // an error occurred while attempting login
            alert("please login first");
          } else if (user) {
            // user authenticated with Firebase
            //alert('User ID: ' + user.id + ', Provider: ' + user.provider);
            $.ajax({
                type: "GET",
                url: "https://graph.facebook.com/"+user.id,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                $('#user').text("Welcome  "+data.name);
                }
            });
          } else {
            // user is logged out
            //auth.login('facebook');
          }
        });
        auth.login('facebook');

在登录时,我也遇到了一个问题,正如您在else我使用的部分中看到的那样auth.login('facebook');,它不起作用显示错误 auth is not defined。但如果我在外面使用它,else它工作正常。

请帮我解决这个问题。

4

1 回答 1

1

与有关的问题不同auth.logout(),您永远不应该auth.login('facebook');在此回调中调用。相反,它应该在用户点击事件之后调用,因为您的浏览器会阻止 Facebook 弹出窗口启动。

来自https://www.firebase.com/docs/security/simple-login-overview.html

第三方身份验证方法使用浏览器弹出窗口提示用户登录、批准应用程序并将用户数据返回给请求应用程序。大多数现代浏览器都会阻止打开此弹出窗口,除非它是由直接用户操作调用的。

因此,我们建议您仅在用户单击时调用第三方身份验证方法的“login()”方法。

于 2013-09-28T20:36:48.277 回答