Sunday, 21 June 2020

Help with Sessions not persisting over Nginx

Hi, I have a Node/Express/Postgre backend API. I'm using the express-session library to handle sessions. I pretty much just give the session the userId when a login is successful, and whenever the home page is visited it checks the users table in the database for a match with req.session.userId- if so the user is redirected to the main page.On my local host the sessions work perfectly and exactly how I would like. However when I've deployed my application to a Digital Ocean Droplet with PM2 and Nginx and the sessions won't persist.The session table in the database gets populated with all of the session data correctly and I even see the userId property get added. The issue seems to be when the request hits my landing page- I try to retrieve req.session.userId and it returns undefined? On local host, this point returns the userId correctly but for some reason on my VPS it can't retrieve this data from the frontend?Could this be an Nginx error? Maybe the way that I reconfigured my database? Perhaps it's an issue with the local host making an external call?

Submitted June 22, 2020 at 05:11AM by backjisceglia

No comments:

Post a Comment