title: passport local type error
body: <p>I'm trying to use passport-local for authentication in my Sails project. In my controller: </p>
  
  <pre><code>passport.authenticate('local', function(err, user, info) {
  
    if ((err) || (!user)) { res.json({message: 'Unable to authenticate'}); return; }
  
    req.login(user, function(err) {
  
      if (err) { res.json({message: 'Unable to login'}); console.log(err); return; }
      res.json({message: 'logging in'});
  
    });
  
  })(req, res);
  </code></pre>
  
  <p>In a config file: </p>
  
  <pre><code>passport.use(new LocalStrategy(function(username, password, done) {
  
    User.findOneByUsername(username).done(function(err, user) {
  
      if (err) { return done(null, err); }
      if (!user) { return done(null, false, { message: 'Incorrect User' }); }
  
      bcrypt.compare(password, user.password, function(err, res) {
  
        if (err) { return done(null, err); }
        if (!res) { return done(null, false, { message: 'Invalid Password'}); }
  
        return done(null, user);
  
      });
    });
  }));
  </code></pre>
  
  <p>The response is 'Unable to Login'. 
  The console output is: [TypeError: Cannot read property 'id' of undefined]</p>
  
  <p>I'm new to passport, and I'm not entirely sure where it's failing, since it seems to actually be finding the user, and comparing the passwords successfully in the config file (some console logs seem to indicate as much). But the req.login callback has an error, which means login is failing even though authentication is succeeding. I'm lost as to why I'm getting this error.</p>