criso / fbgraph

NodeJs module to access the facebook graph api
http://criso.github.io/fbgraph/
1.09k stars 174 forks source link

Is there a way to check if a user is authenticated with express example? #109

Open chopfitzroy opened 7 years ago

chopfitzroy commented 7 years ago

Using the express example in the README I would like to check if the user is logged in at the index and if they are not redirect them to /auth/facebook is there a nice way to handle this?

Cheers.

ffflabs commented 6 years ago

You need to enable the Facebook Login script as shown in https://developers.facebook.com/docs/javascript/examples#login

Then, after initialization, check the user login status. If he isn't logged in, then redirect him:

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    console.log('Logged in.');
  }   else {
    location.href = '/auth/facebook';
  }
});