1

Working on Passport.js authentication and want to display messages to client when login is not successful.

My current logic:

  app.route('/login').post(passport.authenticate('local', { failureRedirect: '/' }),
    (req, res) => {
      res.redirect('/profile')
    });

Also using similar thing in registeration which is working as I intended using connect-flash to display my message.

app.route('/register')
.post((req, res, next) => {
  myDataBase.findOne({ username: req.body.username }, function (err, user) {
    if (err) {
      next(err);
    } else if (user) {
      req.flash('message', 'Username is already registered, please try different username');
      res.redirect('/');
    } else {........

How can I apply similar solution to my login logic? I suppose I need to create a custom callback function but could not figure it out.

enszrlu
  • 31
  • 2

0 Answers0