Logging out of Facebook / Disabling the FB.login () call when the 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 I click the [Login with Facebook] button, I see this message "FB.login () when the user is already connected" in the JS Console .

How to disconnect the user?

+6
source share
3 answers

Use the FB.getLoginStatus method to find out if the user is logged in or not.

If they are already logged in, try hiding the "Login" button. Since the login button will always be visible and will not do anything when pressed when the user is already logged in.

Send link for FB.getLoginStatus

+11
source

Good answer from Abirami, one additional point.

How to disconnect the user?

Disabling a user is accomplished with a call like FB.login () called FB.logout () See: http://developers.facebook.com/docs/reference/javascript/FB.logout/

+4
source

This is a solution that no one talks to anyone about because it highlights the error on Facebook, so be prepared for me to vote ...

FB.login () is called after any user tries to log out if the "autologoutlink" parameter on the javascript facebook button is set to true.

The problem is this:

  <fb:login-button autologoutlink="true" width="200" max-rows="1"></fb:login-button> 

(((autologoutlink = "true")))

When true is set, the login button is always called after the user logs out (FB.login), and you set your window.location to another page, which redirects back to the login page, FB.login is treated as an object, very similar to application developer.

On the console, you will see that FB.login () is always called after the user logs out due to this "autologoutlink" parameter in the facebook Javascript login button error.

Now I'm afraid for the jerk who voted for me, lol ...

YES this is a bug with the javascipt SDK asynchronously all.js script

The secret will be to download the Facebook javascript button without the autologoutlink = "true" parameter, but then use php sdk to load the logout button.

Something like this in php to put the javascript sdk login button, but then send the php exit button to get around the asynchronous error in the Facebook code:

 $user = $facebook->getUser(); $logoutUrl=null; $login_page='replace this for logged in page redirect'; //http://domain.com/loggedin $logout_page='replace this for logged out page redirect'; //http://domain.com/loggedout If ($user){ $logoutUrl = $facebook->getLogoutUrl(array( 'next'=>$logout_page )); $fb_login='<a href="'.$logoutUrl.'">Logout</a>'; }else{ $fb_login='<fb:login-button width="200" max-rows="1"></fb:login-button>'; } 

Use the javascript SDK and

 FB.Event.subscribe('auth.login', function(response) { window.location='$login_page'; }); 

and somewhere on your page

 echo $fb_login; 

Thus, you use the Javascript login and php logout redirect methods, and it will correct the error on the Javascript login button autologoutlink = "true", which we will not use, you just need an image of the exit button and css and FB.login () will no longer be called after FB.logout () every time.

You can see how to cut this whole bunch, I'm sure, but this is a fix that no one wants to tell you.

And now for my Infinite Raid ...

In short, if they start a completely insecure session in the PHP SDK, and they can’t even work with buttons, then do not look at the answers!

You are forced to use what Facebook defines as asynchronous scripts, however they are only one-way security, everyone can trick a domain or capture an insecure session where all payments are processed by the specified fake ergo domain, any Facebook application is completely hacked and they just cracked it know, they just didn’t understand how you can rake you, their BS, except for the word asynchronous, which is NOT safe.

Try to construct everything that is connected using asynchronous JAVASCRIPT, and then make it safe, they can always accuse you of not delivering a button that says that the user is or is not connected in any simple way to today's scenarios and technology .

I'm laughing now.

I assume we are in stackoverflow ...

Personally, I believe that the javascript and php SDk for Facebook should be simple and not force the designer to learn their own crazy methods in social design, but simply provide a method that says YES, the user is registered like that ... or NO user is not like that .. .but Facebook seems to think that they are adobe and con-volute everything that allows us to read a four-story building of books on their personal design philosophy so that they are left without examples and code that you would have to be psychic for debugging, which would only changed after two days After you finish creating your application, which took fourteen years just because they couldn’t deliver and instead wanted to sound like they know what they are doing to cover so many corrections that were made to remove these errors .

How adobe, if it worked, we would not have to do a course in this design, if we?

But since it is shite and spends billions of hours of human resources, I’m sure that at some point you will be forced to pay for qualification in it, because it means that money is no longer needed.

I mean, you should transfer all payments via Facebook in such a way that they can remotely edit their ergo sessions of your ergo application in your database, ergo your payments.

That TF has your Facebook-related payments when what you deliver is what they have to pay for and ultimately brings, saves and delivers more users to them.

The same with Hollywood, they call piracy a free movie on the Internet instead of paying you for free advertising of their products, while Hollywood takes 80 billion and an hour in percent, forbid interest!

Piracy makes money for others by not working for slavery, and is sued or actually paid for it.

Remember this lecture, it will be good for you.

I said a lot lol ...

When everything is clear, you will see where the road leads us.

-4
source

Source: https://habr.com/ru/post/907380/


All Articles