Development · Tip

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's 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
Topic
Authentication
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: Lets auth.site.com authenticate app.site.com and other subdomains without fancy setup

Related

Updated