title: Why does sequelize return 500 [object SequelizeInstance:Users] when connecting to express session?
body: <h2>The Problem:</h2>
  <p>I'm trying to authenticate a user with passport-local strategy. I can successfully retrieve the user from the database, but when I try to redirect to ' / ' and initiate a new session, my server responds with 500 [object SequelizeInstance:Users]</p>
  <h2>Context:</h2>
  <p>I came across the 'connect-session-sequelize' node package and implemented it in my app.js:</p>
  <pre><code>const db = require('./models/db.js');
  const userController = require('./controllers/user');
  const myStore = new SequelizeStore({
    db: db.sequelize,
    table: 'Sessions'
  });
  
  app.use(cookieParser());
  app.use(session({
    secret: process.env.SESSION_SECRET,
    store: myStore,
    resave: false, // per the express-session docs this should be set to false
    proxy: true,
    saveUninitialized: true
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(flash());
  
  app.get('/login', userController.getLogin);
  app.post('/login', userController.postLogin);
  app.get('/signup', userController.getSignup);
  app.post('/signup', userController.postSignup);
  
  db.sequelize.sync({
    force: false,
  }).then(() =&gt; {
    app.listen(app.get('port'), () =&gt; {
      console.log('%s App is running at http://localhost:%d in %s mode', chalk.green('✓'), app.get('port'), app.get('env'));
    });
  });
  </code></pre>
  <p>My routes handling the requests:</p>
  <pre><code>const passport = require('passport');
  const LocalStrategy = require('passport-local').Strategy;
  const db = require('../models/db.js');
  const User = db.user;
  
  passport.serializeUser((user, done) =&gt; {
    console.log('serializing user: ', user);
    done(null, user);
  });
  
  passport.deserializeUser((id, done) =&gt; {
    User.findById(id).then((user) =&gt; {
      done(user);
    });
  });
  
  passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) =&gt; {
    User.findOne({
      where: { email: email.toLowerCase() },
    }).then((user) =&gt; {
      if (!user) {
        return done(null, false, { msg: `Email ${email} not found.` });
      }
      user.comparePassword(password, (err, isMatch) =&gt; {
        if (err) { return done(err); }
        if (isMatch) {
          return done(null, user);
        }
        return done(null, false, { msg: 'Invalid email or password.' });
      });
    });
  }));
  
  exports.postSignup = (req, res, next) =&gt; {
    const errors = req.validationErrors();
    const user = new User({
      username: req.body.name,
      email: req.body.email,
      password: req.body.password
    });
  
    User.findOne({
      where: { email: req.body.email }
    }).then((existingUser) =&gt; {
      if (existingUser) {
        req.flash('errors', { msg: 'Account with that email address already exists.' });
        return res.redirect('/signup');
      }
      user.save((err) =&gt; {
        req.logIn(user, (err) =&gt; {
          req.session.save(() =&gt; res.redirect('/'));
        });
      });
    });
  };
  </code></pre>
  <p>'Users' DB model:</p>
  <pre><code>const bcrypt = require('bcrypt-nodejs');
  
  module.exports = (sequelize, DataTypes) =&gt; {
    const Users = sequelize.define('Users', {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
        allowNull: false,
        unique: true
      },
      username: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true
      },
      email: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true
      },
      password_hash: {
        type: DataTypes.STRING
      },
      password: {
        type: DataTypes.VIRTUAL,
        allowNull: false,
        unique: false,
        set(value) {
          const that = this;
          bcrypt.genSalt(10, (err, salt) =&gt; {
            if (err) { return console.log('BCRYPT GEN SALT ERR:', err); }
  
            bcrypt.hash(value, salt, null, (error, hash) =&gt; {
              if (error) { return console.log('BCRYPT HASH ERR:', err); }
  
              console.log('--&gt; SEQ: BCRYPT hash SET', hash);
              that.setDataValue('password', value);
              that.setDataValue('password_hash', hash);
            });
          });
        }
      }
    });
  
    Users.prototype.comparePassword = function comparePassword(candidatePassword, cb) {
      bcrypt.compare(candidatePassword, this.password_hash, (err, isMatch) =&gt; {
        cb(err, isMatch);
      });
    };
    return Users;
  };
  </code></pre>
  <p>'Sessions' DB model:</p>
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; sequelize
    .define('Sessions', {
      sid: {
        type: DataTypes.STRING,
        primaryKey: true
      },
      userId: DataTypes.STRING,
      expires: DataTypes.DATE,
      data: DataTypes.STRING(50000),
    });
  </code></pre>
  <h2>Server Response:</h2>
  <blockquote>
  <p>POST /login 302 234.474 ms - 46</p>
  <p>Executing (default): SELECT &quot;sid&quot;, &quot;userId&quot;, &quot;expires&quot;, &quot;data&quot;, &quot;createdAt&quot;,
  &quot;updatedAt&quot; FROM &quot;Sessions&quot; AS &quot;Sessions&quot; WHERE &quot;Sessions&quot;.&quot;sid&quot; =
  'Jhmo9YA9MhwKEVa6zWxvvRQGdYoXmdSQ';</p>
  <p>Executing (default): SELECT &quot;id&quot;, &quot;username&quot;, &quot;email&quot;, &quot;password_hash&quot;, &quot;phone&quot;,
  &quot;age&quot;, &quot;gender&quot;, &quot;location&quot;, &quot;createdAt&quot;, &quot;updatedAt&quot; FROM &quot;Users&quot; AS &quot;Users&quot;</p>
  <p>WHERE &quot;Users&quot;.&quot;id&quot; = 'c40d4cd6-4937-4a66-b785-d302e9fa6c40';</p>
  <p>Executing (default): UPDATE &quot;Sessions&quot; SET &quot;expires&quot;='2018-05-10 06:31:42.797
  +00:00',&quot;updatedAt&quot;='2018-05-09 06:31:42.797 +00:00' WHERE &quot;sid&quot; =
  'Jhmo9YA9MhwKEVa6zWxvvRQGdYoXmdSQ'</p>
  <p>[object SequelizeInstance:Users]
  GET / 500 5.420 ms - -</p>
  </blockquote>