Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get profile data from facebook using passport.js authentication?

In the below code the 'console.log('this does not print!')' statement does not execute. It should execute according to the FacebookStrategy.

passport.use( new FacebookStrategy({clientID: FACEBOOK_APP_ID, clientSecret: FACEBOOK_APP_SECRET, callbackURL: "/home"}, function(identifier, profile, done) {

process.nextTick(function () {
  console.log(' This does not print!');
  return done(null, profile);
  }
);}));

Basically, the authentication thru passport-facebook takes place but I am not able to recover any profile data.

app.get('/home', function(req, res){
    console.log(req.user);
    res.render('home', {user: req.user});
});

The above prints 'undefined' which means that the above app.get(...) did not receive the facebook profile data.

What am I doing wrong? Is there anyway to save (get) facebook profile data after authentication?

like image 807
Sangram Singh Avatar asked Sep 03 '25 09:09

Sangram Singh


1 Answers

Above

callbackURL: "/home"

is wrongly declared. It should be:

callbackURL: "/auth/facebook/callback"

for more on this discussion https://github.com/jaredhanson/passport-facebook/issues/47

like image 168
Sangram Singh Avatar answered Sep 04 '25 21:09

Sangram Singh