title: Forcing Sequelize to update req.user in Express route
body: <p>I have a very simple site that is using Passport JS to create local login strategy to hit a local postgres database using the Sequelize ORM.</p>
  
  <p>The user model looks something like this:</p>
  
  <pre><code>module.exports = function(sequelize, DataTypes) {
      return sequelize.define('user', {
          id: {
              primaryKey: true,
              type: DataTypes.UUID,
              defaultValue: DataTypes.UUIDV4
          },
          email: DataTypes.STRING,
          password: DataTypes.STRING,
      }, {
          classMethods: {
              generateHash: function(password) {
                  return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
              },
          },
          instanceMethods: {
              validPassword: function(password) {
                  return bcrypt.compareSync(password, this.password);
              }
          },
          getterMethods: {
              someValue: function() {
                  return this.someValue;
              }
          },
          setterMethods: {
              someValue: function(value) {
                  this.someValue = value;
              }
          }
      });
  }
  </code></pre>
  
  <p>Everything seems to work just fine. I can sign up using this strategy, log in, and see data.</p>
  
  <p>I also am using Express and have various routes set. The <code>req.user</code> appears to be set correctly, as I can interact with all the fields of this object.</p>
  
  <p>Consider the sample route which works correctly:</p>
  
  <pre><code>app.get('/profile', isLoggedIn, function(req, res) {
      res.render('profile.ejs', {
          user : req.user
      });
  });
  </code></pre>
  
  <p>My serialization / deserialization methods:</p>
  
  <pre><code>passport.serializeUser(function(user, done) {
      done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done) {
      User.findById(id).then(function(user) {
          done(null, user);
      }).catch(function(e) {
          done(e, false);
      });
  });
  </code></pre>
  
  <p>So, as per the Passport JS documentation, the user session seems to be correctly set and hooked into Express.</p>
  
  <p>The trouble is that I cannot update any of the fields in the user object.</p>
  
  <p>If I have the following route:</p>
  
  <pre><code>app.get('/change-email', function(req, res) {
      req.user.email = req.body.email;
      res.status(200).end();
  });
  </code></pre>
  
  <p>Nothing happens in the database.</p>
  
  <p>This is very similar to <a href="https://stackoverflow.com/questions/20521795/how-to-update-req-user-session-object-set-by-passportjs">this question</a> except it appears with Sequalize, the user object never persists, even after logging out and back in again.</p>
  
  <p>I have also tried: <code>req.session.passport.user.email = req.body.email</code></p>
  
  <p>Although I didn't think this would fix the problem, I also tried to call <code>login</code> with the new user object, but this generated 500 errors. Which such a limited number of functions that can be called, according to the Passport JS documentation, I'm starting to question if this functionality is even possible.</p>
  
  <p>I'm not sure what to try from here. How can I update my <code>user</code> object using Sequelize?</p>
  
  <p>Any help would be greatly appreciated! Thanks!</p>