I have already implemented the Facebook-LogIn in my website with express js and passport-Facebook. It works well (I get field profile), but the problem is that I don't get the Email. I get an error:
email : profile.emails[0].value,
TypeError: Cannot read property '0' of undefined
My code:
passport.use('facebook',new FacebookStrategy({
clientID : config.facebook.id,
clientSecret : config.facebook.secret,
callbackURL : '/auth/facebook/callback',
profileFields : ['id', 'displayName', 'emails','photos']
}, function(accessToken, refreshToken, profile, done) {
User.findOne({provider_id: profile.id}, function(err, user) {
if(err) throw(err);
if(!err && user!= null) return done(null, user);
var user = new User({
provider_id : profile.id,
name : profile.displayName,
email : profile.emails[0].value,
photo : profile.photos[0].value,
});
user.save(function(err) {
if(err) throw err;
return done(null, user);
});
});
}));
It would be great if someone could help me with the solution to my problem :)