Cookies are not being stored in the browser after deployment (MERN STACK)

Cookies are not being stored in the browser after deployment. I attempted to address the issue by using a full subdomain URL and even tried without specifying a domain, but the problem persists. I am utilizing express-session and passport.js for implement. Backend code deploy on render.

site link : https://authmasterdevchallenge.netlify.app
frontend-repo : GitHub - deep0133/authmaster-frontend: DevChallenge : Implementing the frontend with Vite, React.js and Tailwind CSS for the 'auth-master' challenge.
backend-repo : GitHub - deep0133/authmaster-backend: DevChallenge : Implementing the Backend with Nodejs, Express, Passportjs, for the 'auth-master' challenge.

I don’t believe this has anything to do with cookies. Browsers are not even able to connect to your backend:

Instead of setting CORS headers, you can simply setup Netlify Rewrites: Redirects and rewrites | Netlify Docs

Change your _redirects file: authmaster-frontend/public/_redirects at main · deep0133/authmaster-frontend (github.com) to:

/api/* https://auth-backed-hxu1.onrender.com/:splat 200!
/* /index.html 200

and then, from your frontend, make API requests like: /api/auth/register instead of using the full URL to Render.

On a side note, you can also use Express on Netlify: Express on Netlify | Netlify Docs, which can possibly make this simpler to use instead of managing 2 separate services.

After modifying the ‘_redirects’ file, I attempted to log in and register, but I noticed that the requests are being made from the frontend URL instead of the expected backend URL.

for testing : login page
email : testing@gmail.com
password : 123456

After making further changes to the backend code and the _redirects i.e [ /* /index.html 200 ] file, I am now able to successfully make requests to the backend API. The login process is successful, and I can see the cookie being received in the network tab headers. However, the cookie is not being set in the browser.

This isn’t a Netlify issue. This is explained by th browser if you go to the cookies tab:

Hover on the small i and you’ll see the reason.

“I have set sameSite to none and secure to true , but the cookie is still not being stored and received on the frontend. Here are my frontend login function and express-session settings:”

Sorry to say, but I’d advise you to try debugging the issue on your end, as I’ve been repeteadly saying, this isn’t a Netlify issue, but a coding problem. You should be asking for help on a coding forum.

This time, you’re not sending a response cookie at all:

The response headers are lacking a set-cookie header. Again, this is a problem with your backend on Render and not on Netlify.

1 Like