# Cross-Subdomain Cookies in Better Auth

> Share authentication sessions across multiple subdomains using Better Auth configuration.

This configuration tip shows how to share authentication cookies across multiple subdomains with Better Auth. By setting the root domain under the advanced options, an authentication server on one subdomain can handle sessions for apps on other subdomains.

## How it works

To make auth.site.com your auth server and authenticate other subdomains like app.site.com or your.site.com, enable crossSubDomainCookies in the betterAuth config: advanced: { crossSubDomainCookies: { enabled: process.env.NODE\_ENV === "production", domain: "site.com" } }. This shares cookies between the subdomains.

## What it is for

- Authenticate multiple apps under the same root domain from a single auth server
- Share session states between app subdomains and an auth subdomain
- Avoid complex token-passing setups across internal domain services

## Key points

- Configure crossSubDomainCookies under the advanced settings key
- Set the base domain to allow cookie visibility across all subdomains
- Conditionally enable domain scoping based on environment

## Pricing

Free

## Details

- Type: Tip
- Category: [Development](https://xiry.app/topics/development.md)
- Open source: yes
- Platforms: Code library
- For: Developers using Better Auth across multi-subdomain architectures
- Tags: better auth, cookies, authentication, typescript, subdomains, web dev

## Why it was saved

- [@bekacru, 28 July 2025](https://x.com/bekacru/status/1949675605345349801): Lets auth.site.com authenticate app.site.com and other subdomains without fancy setup

## Related

- [2023 JavaScript Rising Stars](https://xiry.app/resources/2023-javascript-rising-stars): Annual overview of the fastest-growing JavaScript GitHub repositories in 2023. (Website, Free)
- [Better Auth](https://xiry.app/resources/better-auth): Open-source TypeScript authentication framework for modern web applications. (GitHub repo, Open source)
- [Starter.diy](https://xiry.app/resources/starter-diy-2164): Full-stack SaaS starter with Next.js 15, Convex, and Clerk Billing (GitHub repo, Open source)
- [Titan](https://xiry.app/resources/titan): Full-stack Next.js 15 starter with Better-Auth, Drizzle, and Tailwind v4 (GitHub repo, Open source)
- [@json-render/react-pdf](https://xiry.app/resources/json-render-react-pdf): Render structured JSON specifications into PDFs using React PDF (GitHub repo, Open source)
- [Accessing X Internal API via Session Tokens](https://xiry.app/resources/accessing-x-internal-api-via-session-tokens): Tutorial explaining session token replay for internal X API access (Framework, Free)

Updated 11 October 2026. Page: https://xiry.app/resources/cross-subdomain-cookies-in-better-auth

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
