Cookies not saved in production
I have a node/express backend and a vite react frontend. They are on different urls:
Backend: http://my-backend.vercel.app/
auth.ts looks like this:
Frontend: https://my-frontend.vercel.app
On local it works fine. But on production, it calls the api, but the session cookie doesn't get saved.
Can you please help with what's wrong here?
3 Replies
I noticed that when I login from frontend, it does set the cookie, but cookie domain is the backend url. That's why when I refresh the page, it just vanishes. How do I resolve this?
Are your backend and frontend using the same domain?
Then configure cross-domain cookies
https://www.better-auth.com/docs/concepts/cookies#cross-subdomain-cookies
Cookies | Better Auth
Learn how cookies are used in Better Auth.
The problem got resolved by moving from vercel.app to my own custiom domain. On vercel.app, vercel was creating some problem with setting the cookie as per our specs.