How to share cookies between Medusa and the store front in production (DigitalOcean)? #5086
Replies: 3 comments 5 replies
-
The browser will not let you specify a domain name that does not match what the browser is actually accessing. That setting will not let you set a cookie that doesn't match the origin the browser has requested. The browser will just reject it. If you think about it, this makes sense. If browsers allowed this, it would be a massive security issue, and chaos would ensue. The setting exists because the app might not know the domain. It is probably running on localhost and being proxied, all handled by DO. The same domain issue has to do with restrictions in Safari on third-party cookies, which or often used for tracking. If the cookies is coming from a different root domain, Apple assumes it is sketchy. So you want to have the same root domain, which it seems you already do. So the domain name is likely not your issue. Check the browser console Application tab under cookies to see if the cookie is being set. If it is there, then the browser is accepting it. |
Beta Was this translation helpful? Give feedback.
-
The storefront app client runs in the browser, and that part of the app can |
Beta Was this translation helpful? Give feedback.
-
Thanks, I will try to figure it out and will post back once it's resolved, or will come back with more questions. Thank you! |
Beta Was this translation helpful? Give feedback.
-
I'm building a storefront with Nuxt.js and I am having issue maintaining user sessions when I deploy my app to Digital Ocean, but everything works fine locally. I suspect it's due to the fact that on localhost both the Medusa backend as well as the Nuxt front-end share the same domain, thus they can read each other's cookies, whereas once deployed to Digital Ocean, they live on different domains.
Storefront is deployed to http://my-super-store.com (a made up domain name of course) and Medusa is deployed onto a subdomain: http://api.my-super-store.com.
I tried specifying the domain name for the cookie within my front-end code, according to Nuxt's documentation: https://nuxt.com/docs/api/composables/use-cookie#domain, but it does not seem to work.
I tried the following:
None of these seemed to have fixed the problem - as soon as the user logs in from the storefront and refreshes the page, the session is lost, because no cookie is set.
Can anyone help me resolve this? This is a major problem for going live.
Many thanks,
John
Beta Was this translation helpful? Give feedback.
All reactions