I am getting this error when I try to run the server, trying a require for Passport module.
Passport JS -> require(...) is not a function
const passport = require('passport');
require('./config/passport')(passport);
UPDATED Here the passport file
const LocalStrategy = require('passport-local').Strategy;
const User = require('../app/models/user');
module.export = function(passport) {
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
})
});
passport.use('local-signup', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
},
function(req, email, password, done) {
User.findOne({ 'local.email': email }, function(err, user) {
if (err) { return done(err); }
if (user) {
return done(null, false, req.flash('signupMessage', 'El email ya existe'));
} else {
var newUser = new User();
newUser.local.email = email;
newUser.local.password = newUser.generateHash(password);
newUser.save(function(err) {
if (err) { throw err; }
return done(null, newUser);
});
}
})
}));
passport.use('local-login', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true
},
function(req, email, password, done) {
User.findOne({ 'local.email': email }, function(err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, req.flash('loginMessage', 'El email no ha sido encontrado'));
}
if (!user.validatePassword(password)) {
return done(null, false, req.flash('loginMessage', 'Wrong password'));
}
return done(null, user);
})
}));
}
This happens because it thinks you are trying to invoke a function hense your error. is not a function
it requires the passport module and try to invoke it with passport var as an arg.
import passport as a constant,
const passport = require('passport');
UPDATED ANSWER
it seems
you are trying to import './config/passport'
which probably doesn't resolve to a function please refer to
this answer
UPDATED ANSWER #2
seems like you have a typo . try changing module.export
to module.exports
in your passport custom module