Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook logout/disconnect FB.login() called when user is already connected

<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'appID',
            status     : true,
            cookie     : true,
            xfbml      : true,
            oauth      : true,
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>
      <div class="fb-login-button">Login with Facebook</div>

    </body>
</html>

Every time when i click on [Login with Facebook] button i see in JS Console this message "FB.login() called when user is already connected."

How to disconnect user?

like image 997
Sergey L Avatar asked Feb 03 '23 08:02

Sergey L


2 Answers

Use FB.getLoginStatus method to find whether the user in logged in or not.

If they already logged in, try to hide the Login button. Because the login button will be visible always and do nothing on click when the user already logged in.

Refer this link for FB.getLoginStatus

like image 147
Abirami Rajendran Avatar answered Feb 05 '23 17:02

Abirami Rajendran


Good answer from Abirami, one additional item.

How to disconnect user?

Disconnecting a user is done with a call similar to FB.login() called FB.logout() See: http://developers.facebook.com/docs/reference/javascript/FB.logout/

like image 43
DMCS Avatar answered Feb 05 '23 18:02

DMCS