I am working on the login system using passport.js and express with pug templates. I am trying to render the login page with a message on failure, and if on success I want to redirect the user back to the last page they have been to, of which URL is passed as hidden input inside the pug template. I want to then take that value of that hidden input and put it inside the successRedirect, however it says req is not defined:
router.post("/login",
body('backurl').trim().escape(),
passport.authenticate("local", {
successRedirect: (req.body.backurl),
failWithError:true
}), function(err,req,res,next){
return res.render('login', {message: 'Unable to login, the password or the username are wrong'})
}
from my understanding, that happens because of it not having a req since there is no function with req,res,next, so I tried to wrap it with a function that has it:
router.post(“/login”,
body(‘backurl’).trim().escape(),
function(req,res,next){
passport.authenticate("local", {
successRedirect: (req.body.backurl),
failWithError:true
}), function(err,req,res,next){
return res.render('login', {message: 'Unable to login, the password or the username are wrong'})
}
}
);
but it just keeps reloading and doesn’t work and doesn’t go to any URL.
can anybody help me fix this and move the user to the URL from the hidden input while rendering a pug template on failure with variables?
Thanks!