Since I'm landing on the login page from another url, I want the user redirected back to that url when he log on. But in order to do so I can't use passport as a middleware, ie I did
router.post("/login",function(req,res,next){
var redirect= req.query.returnUrl || "index";
passport.authenticate('local', { successRedirect: redirect,
failureRedirect: 'login',
failureFlash: true })(req,res,next);
});
ie I'm calling the middleware function manually, this because I need to extract some info from the request to proper form the redirect url. It works, but I don't know if there is a more compliant way in doing it. Can I use the middleware approach anyway?