Sunday 29 July 2018

Passport.js: authentication seems to work fine, but can't keep users logged in.

I've build a simple app that allows users to log in through google using passport's google strategy and it all works fine.I'm trying to add a local strategy as well, but I can't find a solution.Database works fine as users get created during sign up process.Logging in seems to work initially as I get redirected to "/" as expected with successRedirect: "/". But if I try to go to any other route page, I'm not logged in any longer.I f i run req.isAuthenticated()it returns false. If I try to retrive req.user, it's undefined.Here's the code: https://ift.tt/2uZ43Dc, I tired to get some help on stackoverflow but with no success)It seems like authentication itself works, but somehow it doesn't keep up. If I run a console.log("req.isAuthenticated") right after signing up it returns true, but as soon as I go to another route (example: /), by running a console.log("req.isAuthenticated") in the get request of that route I get a false. It's like I can login but I can't stay logged in. Could this be related to cookies? Did I write something wrong? Does anyone know how to solve?

Submitted July 29, 2018 at 09:17AM by mindnoot

No comments:

Post a Comment