I m developing a backend with nodejs v8.7.0, for the authentication im using passport and local passport , i worked with this before and everything going well , but now i dont know what is the problem, well this is my code :
my strategy :
var passport = require('passport')
var LocalStrategy = require('passport-local').Strategy
passport.use('local', new LocalStrategy({
usernameField: 'email'
},
function (email, password, done) {
User.findOne({
email: email,
is_admin: false
}, function (err, user) {
if (err) {
return done(err)
}
// Return if user not found in database
if (!user) {
return done(null, false, {
message: 'User not found'
})
}
// Return if password is wrong
if (!user.validPassword(password)) {
return done(null, false, {
message: 'Password is wrong'
})
}
// If credentials are correct, return the user object
return done(null, user)
})
}
))
and here is where the call happen :
router.post('/login', (req, res) => {
try {
passport.authenticate('local', function (err, user, info) {
console.log('here xx')
var token;
if (err) {
console.log(err);
return res.status(401).json(err);
}
// If a user is found
if (user) {
console.log('here')
token = user.generateJwt();
return res.status(200).json({
"token": token
});
} else {
// If user is not found
res.status(401).json(info);
}
})
} catch (reason) {
res.status(501).json({
message: reason.message
})
}
})
the problem is that im getting nothing like the message from console.log or anything like errors, its not executing the callback from passport.authenticate.... by the way everything like registering new users and everything is working well anyone can help please ?