Robin M
Robin M

Reputation: 664

Facebook Javascript SDK Logout crashes Facebook application

I'm integrating Facebook login to my application/website and using the standard piece of Javascript code from Facebook : https://developers.facebook.com/docs/facebook-login/web

On first use, everything works ok after granting the website basic permission, the login works fine and the statusChangedCallback() function returns:

Object {status: "connected", authResponse: Object}

However, executing a logout using :

function logout()
{
    FB.logout(function(){document.location.reload();});
}

... seems to irrecoverably crash/destroy the application.

Each subsequent login attempt returns :

Object {authResponse: null, status: "unknown"}

I've tried the following to no effect.

I've determined it's the call to logout causing the problem as the only way to get it working again is to delete the application via the Facebook developers console and create a new app with a new app ID.

Has anybody seen this behaviour before?

Upvotes: 1

Views: 352

Answers (2)

Robin M
Robin M

Reputation: 664

It seems to be that calling the following function responds as I stated above misdirected me into thinking there was an issue:

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

This does repeat the following :

Object {authResponse: null, status: "unknown"}

Howeverm, if I instead use :

FB.login(function(response) {
}

I am able to login after having logged out and more importantly can gain access to the userID returned from facebook to identify the user.

Upvotes: 0

Milan O
Milan O

Reputation: 163

There's a cookie called "fblo_*" created after FB.logout() which seems to be the reason for this. I can't say exactly why it's there and what it does, but deleting it makes the login work again.

Therefor I created a small script that looks for this cookie and deletes it just before I call FB.login() which you probably want to call in a click even anyways (https://developers.facebook.com/docs/reference/javascript/FB.login/v2.5).

function delete_cookie(name) 
{
    document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
}


var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
{
    if(cookies[i].split("=")[0].indexOf("fblo_") != -1)
        delete_cookie(cookies[i].split("=")[0]);
}

Upvotes: 4

Related Questions