Reputation: 998
I'm using the Facebook sdk for javascript in a AngularJS website.
I'm trying to prefill a registration form using a Facebook login. In the first time, the facebook modal appears, I enter my information, it logs in and I get the data I need, as expected.
Then I complete the registration, log in the system. And log out the system, while also performing a Facebook logout.
Then I went back to create a second registration, expecting to test the registration with a different facebook account...
But when I hit Facebook login to prefill the form, instead of the sdk showing up the Facebook login modal again for me to enter a new login, it performed a login with my previous data.
When I went to check the reason, I've discovered that the facebook status says 'connected'. I was expecting to be disconnected, since I've successfully performed a facebook logout.
I'm I wrong in assuming this? How can I disconnect the first user to be able to use a different facebook account on my second registration?
To login, I'm using:
var deferred = $q.defer();
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('already logged in.');
deferred.resolve(response);
}
else {
FB.login( function(response) {
if (response.authResponse) {
console.log('response: ' + JSON.stringify(response));
var access_token = response.authResponse.accessToken;
console.log('access token: ' + access_token);
console.log('Welcome! Fetching your information.... ');
deferred.resolve(response);
} else {
console.log('User cancelled login or did not authorize.');
deferred.reject('Error occured');
}
}, {
scope: 'public_profile, email, user_birthday',
return_scopes: true
});
}
});
return deferred.promise;
And my logout is like:
var deferred = $q.defer();
FB.logout(function(response) {
// I've tried with and without this line of code:
FB.Auth.setAuthResponse(null, 'unknown');
console.log('FB service logged out');
deferred.resolve(response);
});
return deferred.promise;
From this reference Facebook JS SDK FB.logout() doesn't terminate user session I tried to use FB.Auth.setAuthResponse(null, 'unknown');
after the logout, but it didn't work for me.
Upvotes: 2
Views: 742
Reputation: 788
I was having a similar issue and solved it by having a Facebook disconnect button in the user profil which calls the API:
DELETE /{user-id}/permissions/
https://developers.facebook.com/docs/graph-api/reference/user/permissions/
E.g. with the Javascript SDK:
// remove permission, so that the user is asked to authenticate the app again
// or another user can login on the top right of the login popup
FB.api('/me/permissions', 'delete', {
access_token: user.accessToken // use existing token from database
}, (r) => {
if(r.success) user.accessToken = null; // remove token in database
});
Upvotes: 2