title: this.sessionModel.find is not a function when using express-session and connect-session-sequelize
body: <p>I just realized an app I have been working on no longer works when I sign in to the application. After I sign in I get a blank page with  </p>
  
  <p><code>this.sessionModel.find is not a function</code> printed at the top with a 500 error in the console</p>
  
  <p>I am deathly afraid there is something wrong with the packages I am using. Has anyone ever experienced this problem before? I'll add some code snippets below, let me know if I need to provide more info thank you so much in advance. Here is how I am setting up the server:</p>
  
  <pre><code>const path = require('path')
  const express = require('express')
  const morgan = require('morgan')
  const bodyParser = require('body-parser')
  const compression = require('compression')
  const session = require('express-session')
  const passport = require('passport')
  const SequelizeStore = require('connect-session-sequelize')(session.Store)
  const db = require('./db')
  const sessionStore = new SequelizeStore({db})
  const PORT = process.env.PORT || 8080
  const sslRedirect = require('heroku-ssl-redirect')
  const app = express()
  module.exports = app
  
  /**
  this file is where we import middleware, route the routes, sync the db, and start the server.
   */
  if (process.env.NODE_ENV !== 'production') require('../secrets')
  
  // passport registration
  passport.serializeUser((user, done) =&gt; done(null, user.id))
  passport.deserializeUser((id, done) =&gt;
    db.models.user.findById(id)
      .then(user =&gt; done(null, user))
      .catch(done))
  
  const createApp = () =&gt; {
    // logging middleware
    app.use(morgan('dev'))
  
    // body parsing middleware
    app.use(bodyParser.json())
    app.use(bodyParser.urlencoded({ extended: true }))
  
    // compression middleware
    app.use(compression())
  
    // session middleware with passport
    app.use(session({
      secret: process.env.SESSION_SECRET || 'nothing',
      store: sessionStore,
      resave: false,
      saveUninitialized: false
    }))
    app.use(passport.initialize())
    app.use(passport.session())
  
    // auth and api routes
    app.use(sslRedirect())
    app.use('/auth', require('./auth'))
    app.use('/api', require('./api'))
  
    // static file-serving middleware
    app.use(express.static(path.join(__dirname, '..', 'public')))
  
    // any remaining requests with an extension (.js, .css, etc.) send 404
    app.use((req, res, next) =&gt; {
      if (path.extname(req.path).length) {
        const err = new Error('Not found')
        err.status = 404
        next(err)
      } else {
        next()
      }
    })
  
  
    // sends index.html
    app.use('*', (req, res) =&gt; {
      res.sendFile(path.join(__dirname, '..', 'public/index.html'))
    })
  
    // error handling endware
    app.use((err, req, res, next) =&gt; {
      console.error(err)
      console.error(err.stack)
      res.status(err.status || 500).send(err.message || 'Internal server error.')
    })
  }
  
  const startListening = () =&gt; {
    // start listening (and create a 'server' object representing our server)
    const server = app.listen(PORT, () =&gt; console.log(`Serving on port ${PORT}`))
  }
  
  const syncDb = () =&gt; db.sync()
  
  // This evaluates as true when this file is run directly from the command line,
  // i.e. when we say 'node server/index.js' (or 'nodemon server/index.js', or 'nodemon server', etc)
  // It will evaluate false when this module is required by another module - for example,
  // if we wanted to require our app in a test spec
  if (require.main === module) {
    sessionStore.sync()
      .then(syncDb)
      .then(createApp)
      .then(startListening)
  } else {
    createApp()
  }
  </code></pre>
  
  <p>and here are my routes for logging in:</p>
  
  <pre><code>const router = require('express').Router()
  const User = require('../db/models/user')
  module.exports = router
  
  //routes for login authentication
  
  
  //login
  router.post('/login', (req, res, next) =&gt; {
    User.findOne({where: {email: req.body.email}})
      .then(user =&gt; {
        if (!user) {
          res.status(401).send('User not found')
        } else if (!user.correctPassword(req.body.password)) {
          res.status(401).send('Incorrect password')
        } else {
          req.login(user, err =&gt; (err ? next(err) : res.json(user)))
        }
      })
      .catch(next)
  })
  
  //change password
  router.put('/:id/resetpw', (req, res, next) =&gt; {
    User.update(req.body, {
      where: {
        id: req.params.id
      },
      individualHooks: true
    })
      .then(([updatedRows, [updatedUser]]) =&gt; {
        res.status(200).json(updatedUser)
      })
      .catch(next)
  })
  
  //sign up
  router.post('/signup', (req, res, next) =&gt; {
    User.create(req.body)
      .then(user =&gt; {
        req.login(user, err =&gt; (err ? next(err) : res.json(user)))
      })
      .catch(err =&gt; {
        if (err.name === 'SequelizeUniqueConstraintError') {
          res.status(401).send('User already exists')
        } else {
          next(err)
        }
      })
  })
  
  //logout
  router.post('/logout', (req, res) =&gt; {
    req.logout()
    req.session.destroy()
    res.redirect('/')
  })
  
  router.get('/me', (req, res) =&gt; {
    res.json(req.user)
  })
  </code></pre>