Friday 12 January 2018

[Help] Passport and Express Authenticated Redirect

So my function that's not working properly is:function ensureAuthentication(req, res, next){ if(req.isAuthenticated()){ return next(); } else { res.redirect("/"); } } The function that it's called in is:router.get("/adminIntro", ensureAuthentication, function(req, res){ res.render("mainSite/intro"); }); What is happening is taht the ensureAuthentication is redirecting to the 'encorrrect' route. This is happening even after a successful login here:router.post("/login", passport.authenticate("local", { successRedirect: "/", failureRedirect: "/login" }), function(req, res){ }); Any idea where to look where I could solve this issue.To clarify I looked on stack overlfow. There were some suggestions to mix up the order of session and the passport initializer. This caused the whole application to fail. There are some other things that were angular based so they didn't really apply to my specific purpose.I tried another login route that used req.login(). That didn't work either.

Submitted January 12, 2018 at 10:26AM by randygbiv

No comments:

Post a Comment