Search code examples
expresscookiesaxiossafari

Why is my cookie not being saved on Safari but being saved on Chrome?


So I am working on a project, the frontend is on Next.JS hosted on vercel, the backend is on Express.JS hosted on heroku.

I am using express-session along with passport JS to store the sessions.

On the frontend I am using axios for the HTTP calls. The cookie for the session is being saved on Chrome, but on Safari it is not being saved. I have gone through multiple StackOverflow posts but none worked. Safari is receiving the cookie in the header but it is not saving the cookie Cookie being received on Safari

Here is my cors configuration on express cors configuration

What can be the issue here?


Solution

  • Alright, It turns out the reason for this happening is because Safari doesn't allow cross-domain cookies. So, the only true way to resolve this is by hosting the backend and frontend on different subdomains of the same domain.