Facebook logout button and redirect after logout

无人久伴 提交于 2019-12-03 06:32:29
Piskvor

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

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

This function will fire when logout through the FB button happens.

Fernando JS

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

function LogoutFacebook() {    
FB.logout(function (response) {
    window.location = "/facebook/logout/";
});   }
user1052933

Above answer by Piskvor did it for me. Its crazy how many hours I've spend trying to figure this out.

Main problem with plugins such as this Facebook for CakePHP is that they don't come with updates. APIs, especially popular ones like Facebook, change all the time because they are being imporved. If the guy who wrote it initially as a hobby moves on with his life and stops updating the SDK people who are less knowladgable on how to alter these things become stuck.

WORKING CODE:

Nevertheless, thanks for a great solution Piskvor, 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 piece of code here is:

     FB.Event.subscribe("auth.logout", function() {
         window.location = '/users/logout'
     });
    {$callback}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!