JS: Facebook Login button changes states if I login to facebook.com in another tab

南楼画角 提交于 2019-12-24 19:31:30

问题


My Facebook Login button is showing as Logged Out on my site. If I open a new tab in the browser, go to www.facebook.com and sign in successfully, then go back to the my website's tab and refresh the page, the facebook login button now shows as Logged In. Is that the expected behavior here? Seems strange since I never 'clicked' to log in with facebook on my site.

function statusChangeCallback(response) {

  if (response && response.authResponse && response.authResponse.accessToken) {

     Cookies.set("facebookToken",response.authResponse.accessToken, { expires: 7 })
  }

  if (response.status === 'connected') {
    Cookies.set("showFacebookProceed", true)
  } else {
    let element = document.getElementById('fb-proceed');
    element.remove()
    Cookies.remove("showFacebookProceed")

  }
}


checkLoginState = function() {
  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });
};


window.fbAsyncInit = function() {
  FB.init({
    appId      : 'REDACTED', 
    cookie     : true,  
    status     : true,                  
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.8' // use graph api version 2.8
  });
  FB.getLoginStatus(function(response) {
       statusChangeCallback(response);
  });


   FB.Event.subscribe('auth.authResponseChange', function(response) {
        statusChangeCallback(response);
  });



};

// async load of SDK 
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "https://connect.facebook.net/en_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

}

My HTML Button is:

 <div 
   class="fb-login-button"
   data-max-rows="1"
   data-width="314"
   data-auto-logout-link="true"
   data-scope="email"
   data-use-continue-as="true"
   data-button-type="login_with"
 /></div>

回答1:


Yes. This is the expected behavior.

Facebook sdk uses the currently logged in user in your browser. If not logged in, it will ask you to login otherwise no.

You can try the reverse of what you did and test:

  1. Logout of Facebook from browser
  2. Login using Login button in your site

Now if you visit Facebook website you will be logged in as that user even though you logged in from your website. So in both case the same thing is happening.



来源:https://stackoverflow.com/questions/54244589/js-facebook-login-button-changes-states-if-i-login-to-facebook-com-in-another-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!