title: TypeError: Cannot read property 'findOne' of undefined while using sequelize in node
body: <p>I am getting belo mentioned error when trying to make user authentication using passport-local and sequelize for MySQL. When running server it is creating new table in SQL if not already, but as soon as I hit sign up button it is showing error.</p>
  
  <p>Error:</p>
  
  <pre><code>TypeError: Cannot read property 'findOne' of undefined
      at Strategy._verify (E:\Web Development\node-SQL-Sequelize-passport-local\config\passport\passport.js:19:13)
      at Strategy.authenticate (E:\Web Development\node-SQL-Sequelize-passport-local\node_modules\passport-local\lib\strategy.js:88:12)
      at attempt (E:\Web Development\node-SQL-Sequelize-passport-local\node_modules\passport\lib\middleware\authenticate.js:361:16)
      at authenticate (E:\Web Development\node-SQL-Sequelize-passport-local\node_modules\passport\lib\middleware\authenticate.js:362:7)
  </code></pre>
  
  <p>My <strong><code>server.js</code></strong> look like :</p>
  
  <pre><code>app.use(passport.initialize());
  
  app.use(passport.session()); 
  
  
  
  
  //Models
  var models = require("./app/models");
  
  //Routes
  var authRoute = require('./app/routes/auth.js')(app,passport);
  require('./config/passport/passport.js')(passport, models.user);
  
  //Sync Database
  models.sequelize.sync().then(function() {
  
      console.log('Nice! Database looks fine')
  
  }).catch(function(err) {
  
      console.log(err, "Something went wrong with the Database Update!")
  
  });
  
  app.get('/', function(req, res) {
  
      res.send('Welcome to Passport with Sequelize');
  
  });
  </code></pre>
  
  <p>My <strong><code>user.js</code></strong> file:</p>
  
  <pre><code>module.exports = function(sequelize, Sequelize) {
  
      var User = sequelize.define('userInfo', {
  
          id: {
              autoIncrement: true,
              primaryKey: true,
              type: Sequelize.INTEGER
          },
  
          firstname: {
              type: Sequelize.STRING,
              notEmpty: true
          },
  
          lastname: {
              type: Sequelize.STRING,
              notEmpty: true
          },
  
          username: {
              type: Sequelize.TEXT
          },
  
          about: {
              type: Sequelize.TEXT
          },
  
          email: {
              type: Sequelize.STRING,
              validate: {
                  isEmail: true
              }
          },
  
          password: {
              type: Sequelize.STRING,
              allowNull: false
          },
  
          last_login: {
              type: Sequelize.DATE
          },
  
          status: {
              type: Sequelize.ENUM('active', 'inactive'),
              defaultValue: 'active'
          }
  
  
      });
  
      return User;
  
  }
  </code></pre>
  
  <p>My <strong><code>passport.js</code></strong> file :</p>
  
  <pre><code>var bCrypt = require('bcrypt-nodejs');
  
  module.exports = function(passport, user) {
      var User = user;
      var LocalStrategy = require('passport-local').Strategy;
      passport.use('local-signup', new LocalStrategy(
  
      {
          usernameField: 'email',
          passwordField: 'password',
          passReqToCallback: true // allows us to pass back the entire request to the callback
  
      },function(req, email, password, done) {
          var generateHash = function(password) {
  
          return bCrypt.hashSync(password, bCrypt.genSaltSync(8), null);
  
          };
          User.findOne({
          where: {
              email: email
          }
          }).then(function(user) {
  
              if (user)
  
              {
  
                  return done(null, false, {
                      message: 'That email is already taken'
                  });
  
              } else
  
              {
  
                  var userPassword = generateHash(password);
  
                  var data =
  
                      {
                          email: email,
  
                          password: userPassword,
  
                          firstname: req.body.firstname,
  
                          lastname: req.body.lastname
  
                      };
  
  
                      User.create(data).then(function(newUser, created) {
  
                      if (!newUser) {
  
                          return done(null, false);
  
                      }
  
                          if (newUser) {
  
                              return done(null, newUser);
  
                          }
  
                      });
  
              }
  
          });
  
      }
  
  ));
  
  }
  </code></pre>