As i have spent lots of time to find out exactly what is happening in the FB logout, felt better to share it here for others.
First thing, Please read the documentation here
A person logs into Facebook, then logs into your app. Upon logging out from your app, the person is still logged into Facebook.
this point killed 90% my of time. When i have logged in from facebook.com and trying to test login button in my application, it worked as expected, but logout was not terminating the session.
Solution or Fix: As per the scenarios given in the document, it will not terminate the user session, as the login is not initiated from the app, it is from facebook.com. so in this case, fb will not terminate the session.
When you login into fb, from your app (fresh login as username and password), system consider the source/trigger of the session as your app. so when you do logout (window.FB.logout or FB.logout) it will terminate user session completely.
So please logout from facebook.com before testing login functionality in your app.
As other mentioned, use below code to logout
FB.logout(function(response) {
// response from logout will have authResponse with access_token so better to test the status as it will return "unknown"
if(response.status !== "connected") { } \\ do some check on the status of the login before considering successful logout.
});
Last but not least: to test from localhost, please update the settings in FB APP
- Update App Domains to localhost
- Site URL under Websites to http://localhost:3000/
This will solve issues faced in testing from localhost