title: Nodejs passport authentication hanging
body: <p>I'm following a nodejs book here: <a href="https://www.packtpub.com/web-development/mean-web-development" rel="nofollow">https://www.packtpub.com/web-development/mean-web-development</a></p>
  
  <p>All is going smoothly until I try and log in using the passport module. It just hangs with no errors. I have tried other solutions I've found on SO such as re-ordering the middleware, but I think they might be for different versions of Express, as some of the syntax looks slightly different (and doesn't work). Here are the relevant parts. Any help would be greatly appreciated!</p>
  
  <p>Package.json:</p>
  
  <pre><code>{
  "name": "MEAN",
  "version": "0.0.3",
  "description": "First mean app",
  "dependencies": {
    "express":            "~4.8.8",
    "morgan":             "~1.3.0",
    "compression":        "~1.0.11",
    "body-parser":        "~1.8.0",
    "method-override":    "~2.2.0",
    "express-session":    "~1.7.6",
    "ejs":                "~1.0.0",
    "connect-flash":      "~0.1.1",
    "mongoose":           "~3.8.15",
    "passport":           "~0.2.1",
    "passport-local":     "~1.0.0"
  }
  }
  </code></pre>
  
  <p>express.js:</p>
  
  <pre><code>module.exports = function(){
  var app = express();
  
  
  
  if(process.env.NODE_ENV === 'development'){
      app.use(morgan('dev'));
  }else if(process.env.NODE_ENV === 'production'){
      app.use(compress());
  }
  
  app.use(bodyParser.urlencoded({
      extended: true
  }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  
  app.use(session({
     saveUnitialized: true,
     resave: true,
     secret: config.sessionSecret
  }));
  
  
  app.set('views', './app/views');
  app.set('view engine', 'ejs');
  
  app.use(flash());
  app.use(passport.initialize());
  app.use(passport.session());
  
  
  require('../app/routes/index.server.routes.js')(app);
  require('../app/routes/users.server.routes.js')(app);
  
  app.use(express.static('./public'));
  
  return app;
  };
  </code></pre>
  
  <p>passport.js</p>
  
  <pre><code>module.exports = function(){
  
  var User = mongoose.model('User');
  
  passport.serializeUser(function(user, done){
      done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done){
     User.findOne({
         _id: id
     }, '-password -salt'), function(err, user){
         done(err, user);
     }; 
  });
  
  require('./strategies/local.js')();
  };
  </code></pre>
  
  <p>the routing:</p>
  
  <pre><code> app.route('/signin')
      .get(users.renderSignin)
      .post(passport.authenticate('local',{
          successRedirect: '/',
          failureRedirect: '/signin',
          failureFlash: true
      }));
  </code></pre>
  
  <p>Edit: it seems to be the passport.deserializeUser function where things break</p>