2
2 Comments

Node.js Session Management for Single Page App

I'm new to node.js and am trying to figure out how to implement express-sessions with my single page app.

The node.js server is deployed using google cloud app engine.

The single page app is deployed using Netlify and calls the node.js server for all data fetch calls.

I'm using express-session

I'm able to create a session at /login session but future fetch calls (/home) aren't persisting session data.

I'm looking for someone to pair with / help unblock.

Thanks!

  1. 2

    I'm able to create a session at /login session but future fetch calls (/home) aren't persisting session data.

    Is your session token being stored in a cookie? Are you using the fetch() function rather than the older XMLHttpRequest? If so, I would check your fetch calls since it doesnt send cookies by default like an XHR does, so that could be your issue.

    https://stackoverflow.com/questions/34558264/fetch-api-with-cookie

  2. 2

    Hard to say without looking at the code, if I had to guess there's probably an issue with your CORS (+ security) headers and possibly cookie management. Honestly this is the exact reason why session management SaaS providers like Authress exist, but I know it's tempting to try to write something "simple" because it's cheaper.

    My first suggestion would be to paste your issue on Stack Overflow and see if you get any hits, including code examples of course ;), with the alternative being pull in a login/session management solution, they are fairly good value for the money.

Trending on Indie Hackers
Getting first 908 Paid Signups by Spending $353 ONLY. 24 comments I talked to 8 SaaS founders, these are the most common SaaS tools they use 20 comments What are your cold outreach conversion rates? Top 3 Metrics And Benchmarks To Track 19 comments How I Sourced 60% of Customers From Linkedin, Organically 12 comments Hero Section Copywriting Framework that Converts 3x 12 comments Join our AI video tool demo, get a cool video back! 12 comments