I have an application where the user logs in using the facebook account, saving the id, name and email. I'm using link Here is the excerpt:
//Cria um usuario do facebook ou vincula a um usuario ja existente UserSchema.statics.findOrCreateFaceBookUser = function(profile, done) { var User = this; User.findOne({ 'email': profile.emails[0].value }, function(err, user) { if (err) { throw err; } if (user) { user.facebook = { id: profile.id, email: profile.emails[0].value, name: profile.displayName }; user.save(function(err) { if (err) { return next(err); } else { // done(null, user); } }); done(null, user); } else { User.findOne({ 'facebook.id': profile.id }, function(err, user) { if (err) { throw err; } //if (err) return done(err); if (user) { done(null, user); } else { User.create({ firstName:profile.name.givenName, lastName:profile.name.familyName, email: profile.emails[0].value, gender:profile.gender, image:"http://graph.facebook.com/"+profile.id+"/picture?type=normal", facebook: { id: profile.id, email: profile.emails[0].value, name: profile.displayName } }, function(err, user) { if (err) { throw err; } done(null, user); }); } }); } }); };
The problem is that I need to look for facebook friends who are also using the application, but the id returned by facebook graph does not match what I'm persisting in the application.
Any ideas?