I have a problem when the page is not redirected when I try to log in using my passport. Return authorization true(correct username, password).
I'm sure it is somewhere inside my function validPassword, but I'm definitely not sure.
Entry route
app.get('/login', function (req, res) {
res.render('login', {});
});
Login
app.post('/login',
passport.authenticate('local', { successRedirect: '/',
failureRedirect: '/login' }));
User prototype
User.prototype.validPassword = function(username, unhashedPassword) {
async.waterfall([
function (callback) {
User.find({ "username" : username }, function (err, data) {
if(err) return handleError(err);
callback(null, data);
});
},
function (data, callback) {
var isGood = passwordHash.verify(unhashedPassword, data[0].password);
callback(null, isGood);
}
], function (err, result) {
return result;
});
};
Local strategy
passport.use(new LocalStrategy(
function(username, password, done) {
var unhashedPassword = password;
var passedUsername = username;
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(passedUsername, unhashedPassword)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
No errors are printed on my console, so I'm a bit puzzled. Is it possible to return isGoodin the wrong format? Any help would be great.