0

I am using Passport authentication with 'local' strategy for my application. I want the user to be able to know if the username and password entered by user is invalid and if valid then redirect to dashboard. This is how i am authenticating the user:

router.post('/login', passport.authenticate('local', {failureRedirect: '/login', failureFlash: 'Invalid username or password.'}), function(req, res, next){
    res.redirect('/users/dashboard');
});

Redirect part works fine, but the user enters invalid user/pass the flash message in failureFlash: 'Invalid username or password.' dosent show up on the login page. This is how i handle my login route:

router.get('/login', function(req, res, next) {
  res.render('pages/login', {'title' : 'VoteCenter - Login', message: req.flash('message')});
});

What do i need to use in req.flash('??????') to intercept the flash mesaage coming from failureFlash?

Robin
  • 8,162
  • 7
  • 56
  • 101
chirag_lad
  • 229
  • 1
  • 16
  • Possible duplicate of [How to send flash messages in Express 4.0?](http://stackoverflow.com/questions/23160743/how-to-send-flash-messages-in-express-4-0) – C.Raf.T Aug 09 '16 at 06:23

1 Answers1

0

You can get message through req.flash('error')(default)

also you can pass failureFlash object with your custom message name like it:

failureFlash: { type: 'authError', message: 'Invalid username or password.'}

then get message req.flash('authError')

Yrysbek Tilekbekov
  • 2,685
  • 11
  • 17