Facebook logout button and redirect after logout

I am using this code

<fb:login-button autologoutlink="true" perms="user_likes" size="large"></fb:login-button> 

to create the fb login / logout button. Everything works, after entering the system, the login button becomes the exit button. But if the user presses the exit button, the current page is not refreshed, so all the things that should appear only when the user is authenticated still exist until the page refresh is manually updated.

This does not happen if I get the exit URL (Javascript SDK)

 $logoutUrl = $facebook->getLogoutUrl(); 

and then do the logout button yourself; in this case, the correct "next" parameter is passed (with the address of the current page), and the current page reloads.

I would still like to use the first solution, is it possible to use its β€œnext” parameter?

+8
facebook logout
source share
3 answers

Do the redirection yourself - add this in JavaScript, somewhere after FB.init() :

 <script> FB.Event.subscribe("auth.logout", function() {window.location = '/logout'}); </script> 

This function is triggered when you exit the system through the FB button.

+14
source share

The above answer Piskvor did this for me. Its crazy how many hours I spent trying to figure it out.

The main problem with plugins like Facebook for CakePHP is that they do not come with updates. APIs, especially popular ones like Facebook, are constantly changing because they are very important. If the guy who wrote it first as a hobby moves with his life and stops updating the SDK, people who are less aware of how to change these things get stuck.

WORKING CODE:

However, thanks for the excellent Piskvor solution, here is my piece of code for

 apps/plugins/facebook/views/helpers/facebook.php $init .= $this->Html->scriptBlock( <<<JS window.fbAsyncInit = function() { FB.init({ appId : '{$appId}', session : {$session}, // don't refetch the session when PHP already has it status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); FB.Event.subscribe("auth.logout", function() { window.location = '/users/logout' }); {$callback} }; 

The key element of the code is:

  FB.Event.subscribe("auth.logout", function() { window.location = '/users/logout' }); {$callback} 
+1
source share

For integrated authentication (Facebook + Asp.Net MVC) I just use Javascript and FormsAuthentication.SignOut();

 function LogoutFacebook() { FB.logout(function (response) { window.location = "/facebook/logout/"; }); } 
+1
source share

All Articles