Recently, I was in trouble with receiving the flash message from passport.js on failure redirect.
router.post('/login', passport.authenticate('local-login', { successRedirect: '/users/admin',
failureRedirect: '/users',
failureFlash: true })
);
I tried to display the flash message that mentions the invalid username or password on the login page. However, the flash message always displays blank array of flash messages ( {} ).
router.get('/', function(req, res, next) {
res.render('login', { title: 'Login | Lab Report', error: req.flash('error') });
});
Later, I figured out the problem with my configuration of the session. It was the matter of setting the maxAge for the cookie; It was set only for 60 milliseconds. So, I solved my problem by setting the cookie's maxAge to 1000 * 60 * 60 (1hr). Is it funny? I feel it xD
app.use(session({
resave: true,
saveUninitialized: true,
secret: 'michael10devel',
cookie: { maxAge: 1000 * 60 * 60 }
}));
Written By: Michael Devel
Date: 24th, Oct 2017
No comments:
Post a Comment