Here is a get route and I have stored the previous link where it was redirected from in the req.session object under returnTo. After redirecting it hits the /login and we can see the object in the console.
router.get('/login', (req, res) => {
console.log('get in user route..', req.session)
res.render('users/login')
})
req.session :
router.post('/login', passport.authenticate('local', { failureFlash: true, failureRedirect: '/login' }), (req, res) => {
req.flash('success', 'Welcome back!')
const redirectUrl = req.session.returnTo || '/campgrounds'
res.redirect(redirectUrl)
})
But after submitting the login details it always goes to the /campgrounds route.
