. #1794

Closed
opened 2026-03-13 09:03:59 -05:00 by GiteaMirror · 1 comment
Owner

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

Originally created by @bysuma on GitHub (Aug 27, 2025).
Author
Owner

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

Hi @bysuma! I'm Dosu and I’m helping the better-auth team.

Cookies can't be set across subdomains on Vercel's default .vercel.app domain because browsers treat public suffixes like .vercel.app as insecure for cross-domain cookies. This is a browser security restriction, not a Better Auth bug. For reliable cross-subdomain authentication, you need to use a custom domain (like .yourdomain.com) for both your frontend and backend apps on Vercel. Setting the cookie domain to .vercel.app will not work in most browsers, especially Safari (discussion, docs).

If you must use different domains (even with custom domains), make sure:

  • Your cookies are set with SameSite: "none" and Secure: true (example)
  • Your frontend fetches use credentials: "include"
  • Your backend CORS config allows credentials and includes your frontend domain in trustedOrigins (docs)

For local development, you can keep your current setup, but for production on Vercel, switch to custom domains for both apps and set domain: ".yourdomain.com" in your Better Auth config. This will ensure cookies are set and shared as expected.

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): <!-- Greeting --> Hi @bysuma! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Cookies can't be set across subdomains on Vercel's default `.vercel.app` domain because browsers treat public suffixes like `.vercel.app` as insecure for cross-domain cookies. This is a browser security restriction, not a Better Auth bug. For reliable cross-subdomain authentication, you need to use a custom domain (like `.yourdomain.com`) for both your frontend and backend apps on Vercel. Setting the cookie domain to `.vercel.app` will not work in most browsers, especially Safari ([discussion](https://github.com/better-auth/better-auth/discussions/2826), [docs](https://better-auth.com/docs/concepts/cookies)). If you must use different domains (even with custom domains), make sure: - Your cookies are set with `SameSite: "none"` and `Secure: true` ([example](https://github.com/better-auth/better-auth/issues/3470)) - Your frontend fetches use `credentials: "include"` - Your backend CORS config allows credentials and includes your frontend domain in `trustedOrigins` ([docs](https://better-auth.com/docs/concepts/cookies)) For local development, you can keep your current setup, but for production on Vercel, switch to custom domains for both apps and set `domain: ".yourdomain.com"` in your Better Auth config. This will ensure cookies are set and shared as expected. <!-- 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/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b45536f1-42da-4d27-8d56-4564422a8a42?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/4269)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1794