Cookies set in frontend (Vercel) are lost after refresh the page when backend is deployed on Render #6262
Replies: 3 comments 1 reply
|
I got my solution and understood the concepts! |
|
Pretty sure this is third-party cookie blocking, not your cookie config. Before assuming it's the domain thing though, worth double checking a couple things:
If all that checks out and it's still not sticking, it's the domain split. Easiest real fix is putting both under the same parent domain (something like If you can't do that for whatever reason, other options are proxying the API through the frontend's domain (Vercel rewrites, or a Next.js route that just forwards the request) so it looks same-origin to the browser, or dropping cookies entirely for this and sending the token in an |
|
Since you're new to this - your config's mostly right (secure + sameSite: none is correct for cross-site), but check two things: sameSite: 'none' requires secure: true unconditionally in the browser, so if NODE_ENV isn't literally 'production' on Render, the cookie gets silently rejected by the browser. And probably the real one - Render sits behind its own proxy, so Express doesn't see the connection as secure unless you set app.set('trust proxy', 1). Add trust proxy and confirm NODE_ENV is actually production in Render's dashboard, not just your local .env. |
Uh oh!
There was an error while loading. Please reload this page.
# Cookies Set in Frontend (Vercel) are Lost After Page Refresh When Backend is Deployed on Render
Issue Description:
I am experiencing an issue where cookies set in the frontend (deployed on Vercel) are lost upon refreshing the page. The backend is deployed on Render, and it seems that the cookies are not persisting correctly. I suspect this might be related to how the cookies are being configured in the backend.
Backend Configuration:
.env File:
index.js or app.js Code:
Auth Controller - Cookies Options:
Notes:
I am new to backend development and currently learning the basics, so.
Request for Help:
Any guidance, suggestions, or resources for debugging and resolving this issue would be greatly appreciated. I would also love to learn from you about the best practices for handling cookies in this setup 0_0.
Thank you in advance for your assistance!
All reactions