Skip to content

Commit 6e36cf9

Browse files
committed
fixed login errors
1 parent 3750b43 commit 6e36cf9

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

config/strategies/local.strategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(){
1010
passReqToCallback : true // allows us to pass back the entire request to the callback
1111
},
1212
function(req, email, password, done){
13-
authCtrl.fetch(email, password, done)
13+
authCtrl.fetch(req, email, password, done)
1414
}));
1515

1616
}

controller/auth.server.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var authModel = require('../models/auth.server.model.js');
22

33

44
exports.create = function(req, res){
5-
console.log(authModel);
5+
//console.log(authModel);
66
// var newAuth = new authModel({
77
// email: req.body.email,
88
// firstName: req.body.firstName,
@@ -29,19 +29,19 @@ exports.create = function(req, res){
2929
});
3030
})
3131
};
32-
exports.fetch = function(email, password, done){
32+
exports.fetch = function(req, email, password, done){
3333
authModel.findOne({email:email}, function(err, user){
3434
// if there are any errors, return the error before anything else
3535
if (err)
3636
return done(err);
3737

3838
// if no user is found, return the message
3939
if (!user)
40-
return done(null, false, req.flash('loginMessage', 'No user found.')); // req.flash is the way to set flashdata using connect-flash
40+
return done(null, false); // req.flash is the way to set flashdata using connect-flash
4141

4242
// if the user is found but the password is wrong
4343
if (!user.validPassword(password))
44-
return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.')); // create the loginMessage and save it to session as flashdata
44+
return done(null, false); // create the loginMessage and save it to session as flashdata
4545

4646
// all is well, return successful user
4747
return done(null, user);

routes/authRoutes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ authRoutes
2626
user: req.user
2727
});
2828
} else {
29+
2930
return authCtrl.create(req, res);
3031
}
3132
})
3233
.post('/login/', passport.authenticate('local', {
3334
failureRedirect: '/login',
34-
failureFlash: true }),
35+
failureFlash: 'Invalid password or username' }),
3536
function(req, res){
3637
res.redirect('/');
3738
})

0 commit comments

Comments
 (0)