Cookies not being set on Vercel (works on localhost) #1795

Closed
opened 2026-03-13 09:04:00 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @NicolasCassunde on GitHub (Aug 27, 2025).

Hi! I have a Turborepo application and it works perfectly on localhost, but on Vercel the cookie is not being set.

`apps/web
apps/api

packages/auth
packages/db
`

advanced: { crossSubDomainCookies: { enabled: true, domain: ".vercel.app" // https://better-turbo-backend.vercel.app/ //// https://better-turbo-web.vercel.app } }

Originally created by @NicolasCassunde on GitHub (Aug 27, 2025). Hi! I have a Turborepo application and it works perfectly on localhost, but on Vercel the cookie is not being set. `apps/web apps/api packages/auth packages/db ` `advanced: { crossSubDomainCookies: { enabled: true, domain: ".vercel.app" // https://better-turbo-backend.vercel.app/ //// https://better-turbo-web.vercel.app } } `
GiteaMirror added the bug label 2026-03-13 09:04:00 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 27, 2025):

Cookies aren't being set on Vercel because browsers block cookies on public suffix domains like .vercel.app for security reasons—this prevents cookies from leaking across unrelated apps on the same platform. This is enforced both by browsers and by Better Auth's design, so setting domain: ".vercel.app" won't work for cross-subdomain cookies on Vercel (details).

To fix this, you need to use a custom domain (e.g., yourdomain.com) for both your frontend and backend, and set domain: ".yourdomain.com" in your Better Auth config. Also, make sure your cookies are set with SameSite: "none" and Secure: true for cross-domain scenarios (reference). On the frontend, always use credentials: "include" in your fetch requests.

If you stay on .vercel.app, cross-subdomain cookies simply won't work due to these platform and browser restrictions (docs).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 27, 2025): <!-- Answer --> Cookies aren't being set on Vercel because browsers block cookies on public suffix domains like `.vercel.app` for security reasons—this prevents cookies from leaking across unrelated apps on the same platform. This is enforced both by browsers and by Better Auth's design, so setting `domain: ".vercel.app"` won't work for cross-subdomain cookies on Vercel ([details](https://github.com/better-auth/better-auth/discussions/3505)). To fix this, you need to use a custom domain (e.g., `yourdomain.com`) for both your frontend and backend, and set `domain: ".yourdomain.com"` in your Better Auth config. Also, make sure your cookies are set with `SameSite: "none"` and `Secure: true` for cross-domain scenarios ([reference](https://github.com/better-auth/better-auth/issues/3470)). On the frontend, always use `credentials: "include"` in your fetch requests. If you stay on `.vercel.app`, cross-subdomain cookies simply won't work due to these platform and browser restrictions ([docs](https://better-auth.com/docs/concepts/cookies)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1e55f9df-b088-4aec-8b03-583dca6fc46d?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4270)
Author
Owner

@jeremycharron commented on GitHub (Sep 21, 2025):

Hi @NicolasCassunde, same issue here, did you manage to find a solution?

Edit: After some research, it seems that it's not possible to assign a cookie to the vercel.app domain, since it's part of the Public Suffix List. I've bought a cheap domain name and updated the config and it works perfectly.

@jeremycharron commented on GitHub (Sep 21, 2025): Hi @NicolasCassunde, same issue here, did you manage to find a solution? Edit: After some research, it seems that it's not possible to assign a cookie to the vercel.app domain, since it's part of the [Public Suffix List](https://publicsuffix.org/). I've bought a cheap domain name and updated the config and it works perfectly.
Author
Owner

@himself65 commented on GitHub (Sep 24, 2025):

Please customize your domain with a subdomain. It's not possible due to the browser security issue.

https://vercel.com/guides/can-i-set-a-cookie-from-my-vercel-project-subdomain-to-vercel-app

@himself65 commented on GitHub (Sep 24, 2025): Please customize your domain with a subdomain. It's not possible due to the browser security issue. https://vercel.com/guides/can-i-set-a-cookie-from-my-vercel-project-subdomain-to-vercel-app
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1795