title: passportjs local strategy not getting called
body: <p>I am using express and passport to build a rest api backend and it seems that my localStrategy is not getting called on request.</p>
  
  <p>The entry point of my application looks like the following:</p>
  
  <p><em>app.js</em></p>
  
  <pre><code>var fs = require('fs');
  var express = require('express');
  var mongoose = require('mongoose');
  var passport = require('passport');
  var config = require('./config/config');
  
  var morgan       = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser   = require('body-parser');
  
  var app = express();
  
  app.use(morgan('dev')); // log every request to the console
  app.use(cookieParser()); // read cookies (needed for auth)
  app.use(bodyParser.urlencoded({extended:true})); 
  
  app.use(passport.initialize());
  
  //connect to mongodb
  mongoose.connect(config.db, options);
  
  //load models (shorten forEach)
  ...
  require(__dirname + '/models/' + file)(mongoose);
  
  //load passport config
  require('./config/passport')(mongoose, passport);
  
  //load routes
  require('./config/routes')(app, passport);
  
  //start server
  var server = app.listen(3000, ....
  </code></pre>
  
  <p><em>routes.js</em></p>
  
  <pre><code>...
  app.post('/auth', function(req, res){
      console.log("reached auth endpoint");
      console.log(req.body);
      passport.authenticate('local', { session: false}, function(err, user, info){
        console.log("Test:"+user);
        if(err) {
          console.log("Error1");
          return next(err)}
        if(!user){
          console.log("Error2");
          return res.json(401, {error: 'Auth Error!'});
        }
        console.log("Error3");
        var token = jwt.encode({ username: user.email }, "hanswurst");
        res.json({token: token});
      }),
      function(req, res){
        console.log("passport user", req.user);
      };
    });
  </code></pre>
  
  <p><em>passport.js</em></p>
  
  <pre><code>...
  passport.use(new LocalStrategy({
      usernameField: 'email',
      passwordField: 'password',
      passReqToCallback: true
    },
    function(email, password, done){
      console.log("TEST");
      User.findOne({'email': email}, function(err, user){
        if(err){
          console.log("Unknown error");
          return done(err);
        }
        if(!user){
          console.log("No User found");
          return done(null, false);
        }
        if(!user.validPassword(password)){
          console.log("Password was incorrect");
          return done(null, false);
        }
        console.log("User was found");
        return done(null, user);
      });
    }
  ));
  </code></pre>
  
  <p>The only result i get on form request is</p>
  
  <pre><code>reached auth endpoint
  { email: 'test@mail.com', password: 'secret' }
  POST /auth - - ms - -
  </code></pre>
  
  <p>For me the request body looks fine and it should enter my LocalStrategy. I am bit helpless as i am not getting any other console output from this point. </p>