title: passport serialize user into session
body: <p>I'm getting this error when trying to login to my app:</p>
  
  <p>Error: Failed to serialize user into session</p>
  
  <p>The problem is that it is reading parameter user.id as undefined. If I change it to the id value the user has in the database login works.</p>
  
  <pre><code>passport.serializeUser(function(user, done) {
          done(null, user.id);
  });
  </code></pre>
  
  <p>Any ideas on why am I getting my user value as undefined?</p>
  
  <p>pasport local login:</p>
  
  <pre><code>    // =========================================================================
      // LOCAL LOGIN =============================================================
      // =========================================================================
      passport.use(
          'local-login',
          new LocalStrategy({
              usernameField : 'username',
              passwordField : 'password',
              passReqToCallback : true // allows us to pass back the entire request to the callback
          },
          function(req, username, password, done) {
              if(username == "" || password == ""){
                  return done(null, false, req.flash('loginMessage', 'Please fill in all blank fields to login.'));
              }else{
                  query.login(req, username, password, done);
              }
          })
      );
  </code></pre>
  
  <p>login query:</p>
  
  <pre><code>    login: function(req, username, password, done) {
          connection.query("SELECT * FROM users WHERE username = ?",[username], function(err, rows){
              if (err)
                  return done(err);
              if (!rows.length)
                  return done(null, false, req.flash('loginMessage', 'Sorry, username/password do not match.')); // req.flash is the way to set flashdata using connect-flash
  
              // if the user is found but the password is wrong
              if (!bcrypt.compareSync(password, rows[0].password))
                  return done(null, false, req.flash('loginMessage', 'Sorry, username/password do not match.')); // create the loginMessage and save it to session as flashdata
  
              // all is well, return successful user
              return done(null, rows[0]);
          });
      }
  </code></pre>
  
  <p>Login was working until I changed some field names on my database but I updated all my queries with the new names of the fields so I do not know whats happening.</p>