Hey everyoneI've recently integrated Passport js into my app, but am struggling to set up login sessions. When logging in, serializeUser is called properly and req.user is present. On any subsequent request from the browser, however, req.user returns undefined and deserializeUser is not called.When testing with postman, everything seems to work perfectly and requests can access req.user fine. This leads me to believe that passport is set up correctly in the back-end, and the issue lies with either CORS, some express setup, or cookies. Below is what I have to handle CORS.app.use(function(req, res, next) { res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Origin', req.headers.origin); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'); if ('OPTIONS' == req.method) { res.sendStatus(200); } else { next(); } I'm fairly new to CORS and working with login sessions, so I might be missing something incredibly simple. Here is my full repo if anyone wants to take a peek (on branch Login-Backend): https://github.com/SabrinaSnider/ChowThanks for any help!
Submitted May 04, 2020 at 07:17AM by missingJacket
No comments:
Post a Comment