mysql - TypeError: Cannot read property 'findOne' of undefined while using sequelize in node -


i getting belo mentioned error when trying make user authentication using passport-local , sequelize mysql. when running server creating new table in sql if not already, hit sign button showing error.

error:

typeerror: cannot read property 'findone' of undefined     @ strategy._verify (e:\web development\node-sql-sequelize-passport-local\config\passport\passport.js:19:13)     @ strategy.authenticate (e:\web development\node-sql-sequelize-passport-local\node_modules\passport-local\lib\strategy.js:88:12)     @ attempt (e:\web development\node-sql-sequelize-passport-local\node_modules\passport\lib\middleware\authenticate.js:361:16)     @ authenticate (e:\web development\node-sql-sequelize-passport-local\node_modules\passport\lib\middleware\authenticate.js:362:7) 

my server.js :

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 database update!")  });  app.get('/', function(req, res) {      res.send('welcome passport sequelize');  }); 

my user.js file:

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;  } 

my passport.js file :

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 pass entire request 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 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);                          }                      });              }          });      }  ));  } 

review example: github.com/sequelize/express-example. in particular models/index.js models load.

that way handled in example is:

require('./config/passport/passport.js')(passport, models.userinfo); 

because "userinfo" defined in model user.js:


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -