Wednesday, 1 August 2018

[Question] PassportJS - isAuthenticated still allows functions in route to run

I set up my authentication with PassportJS utilizing a local strategy. Everything works great except for one thing: I have functions in my routes that are reliant on variable stored in req.session.passport.user.username and my application breaks when I get an authenticated route when not logged in, displaying an error "Cannot read property 'username' of undefined".I was under the impression that the route argument "isAuthenticated" would prevent a route from running if the user was not logged in. However it seems that it still runs everything in the route, then decides the user is not authenticated, then redirects(but by that point it is broken).Any insight would be greatly appreciated.

Submitted August 01, 2018 at 06:08PM by onlyslavesobey

No comments:

Post a Comment