bbbonthemoon
bbbonthemoon

Reputation: 1778

FaceBook Javascript SDK OAuth authorization when user already logged in on FB

I'm trying to find solution for situation when user is logged out from my app, but still is logged in on facebook, and trying to log in via OAuth to my app again.
I'm checking authorization status by listening to 'auth.login' event.
When user in this situation clicks facebook-connect button, pop-up fires up, gets self-closed and then nothing happens(because user was already logged in on facebook, login event is not fired). If I add getLoginStatus() check, then user gets logged in automatically to my app, when opening the page, even if he didnt click facebook-connect button(thats what I dont want) Any ideas? Thanks!

Upvotes: 0

Views: 250

Answers (1)

Adeel Aslam
Adeel Aslam

Reputation: 11

Specify here your execution code when user already logged in this FB event.

 FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
   // the user is logged in and has authenticated your
   // app, and response.authResponse supplies
   // the user's ID, a valid access token, a signed
   // request, and the time the access token 

   // and signed request each expire
    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;

 } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
  } else {
    // the user isn't logged in to Facebook.
  }
});

Upvotes: 1

Related Questions