Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB.Event.subscribe('auth.login', function(response) { }) issue

FB.Event.subscribe('auth.login', function(response) {
FB.api('/me', function(response){
    //Some operation
});});

Above piece of JavaScript code runs when user logs-in through Facebook

or

when user is already logged-in the browser and you open the page containing the above JavaScript.

Is there any way to execute the operation only when user logs-in for first time and escape the operation when user is already logged-in in the browser?

like image 618
Wentworth Avatar asked Sep 23 '26 04:09

Wentworth


1 Answers

Run FB.getLoginStatus to see if the user is already connected to your app and logged in. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

FB.getLoginStatus(function(response) {
  if (response.session) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, someone you dont know
  }
});
like image 50
Jeff Sherlock Avatar answered Sep 26 '26 01:09

Jeff Sherlock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!