Reputation: 1490
I am facing a weird issue, my app is logged in using user's fb credentials but I cant get to see his email, name or id etc. Here is what I am doing in my users.js route :-
router.get('/auth/facebook',passport.authenticate('facebook', {scope: ['email', 'user_friends']}));
router.get('/auth/facebook/callback',
passport.authenticate('facebook',{ successRedirect:'/profile',failureRedirect:'/'},function(req,res){
console.log("in passport req"); //doesn't get printed
console.log(req);
}));
And in my config/passport.js I am doing :-
var configAuth=require('./auth'); //holds all appID, secret and successurl
var FacebookStrategy=require('passport-facebook').Strategy;
var passport=require('passport');
module.exports=function(passport){
passport.use(new FacebookStrategy({
clientID: configAuth.facebookAuth.clientID,
clientSecret: configAuth.facebookAuth.clientSecret,
callbackURL: configAuth.facebookAuth.callbackURL,
profileFields: ['id', 'displayName', 'photos', 'email']
},
function(accessToken, refreshToken, profile, cb) {
console.log("the user's credentials are: "); //doesn't get printed
console.log(profile.user);
}
));
};
And everything is working fine I am being redirected to successURL but how can I get the user info cause without it everything is in vain, any help will be appreciated. There are no errors in the console.
Upvotes: 1
Views: 355
Reputation: 2135
check req.user
app.get('login',
passport.authenticate('facebook', {
failureRedirect:'/'
}),
function(req, res, next){
//check req.user
console.log('user should be',req.user);
res.redirect('/profile')
});
Upvotes: 4