I have a node project that uses express and passport. Right now, I have it set up to redirect the user to the login page if they are not signed in. So if the user tries to go to /finance, but they are not logged in, then it would take them to /login. But when they log in, I want it to take them to the /finance page or whichever page they originally tried to get to. Right now, it is just taking them to home when they login.
isAuthenticated.js
module.exports = ({user, url}, res, next) => {
if (user != null) {
next()
} else {
res.redirect('/login') // <-- This needs to pass the target url to POST /login in html-routes.js
}
}
html-routes.js
app.post('/login', passport.authenticate('local', {
successRedirect: '/', // <-- This needs to take me to the target url.
failureRedirect: '/login',
failureFlash: true
}))