sails.js + passport.js : managing sessions <p>I am trying to implement a facebook connection in sails using passport. Therefore, I've created a passport.js file in my services folder, the code is given below. It looks like the login is done successfully, however the user serialization doesn't seem to work as the console.log that I put in it never appears in the console and I cannot access the user id trhough req.user once the user is supposed to be logged in. Did anyone managed to get passport working with sails?</p> <pre><code>var passport = require('passport') , FacebookStrategy = require('passport-facebook').Strategy, bcrypt = require('bcrypt'); // helper functions function findById(id, fn) { User.findOne(id).done( function(err, user){ if (err){ return fn(null, null); }else{ return fn(null, user); } }); } function findByUsername(u, fn) { User.findOne({ username: u }).done(function(err, user) { // Error handling if (err) { return fn(null, null); // The User was found successfully! }else{ return fn(null, user); } }); } // Passport session setup. // To support persistent login sessions, Passport needs to be able to // serialize users into and deserialize users out of the session. Typically, // this will be as simple as storing the user ID when serializing, and finding // the user by ID when deserializing. passport.serializeUser(function(user, done) { console.log("utilisateur serilizé!"); done(null, user.uid); }); passport.deserializeUser(function(id, done) { //console.log("coucou"); findById(id, function (err, user) { done(err, user); }); }); // Use the LocalStrategy within Passport. // Strategies in passport require a `verify` function, which accept // credentials (in this case, a username and password), and invoke a callback // with a user object. // using https://gist.github.com/theangryangel/5060446 // as an example passport.use(new FacebookStrategy({ clientID: 'XXX', clientSecret: 'XXX', callbackURL: "http://localhost:1337/callback" }, function(accessToken, refreshToken, profile, done) { User.findOne({uid: profile.id}, function(err, user) { if (err) { return done(err); } if (user) { //console.log('momo'); User.update({uid : user.uid},{token : accessToken},function(){done(null, user);}); } else { console.log(profile); var user_data = { token : accessToken , provider: profile.provider , alias: profile.username , uid: profile.id , created: new Date().getTime() , name: { first: profile.name.givenName , last: profile.name.familyName } , alerts: { email: true , mobile: false , features: true } }; console.log(user_data); User.create(user_data).done(function(err, user) { console.log(err); if(err) { console.log("err");throw err; } done(null, user); }); } }); } )); </code></pre>