© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
crossSubDomainCookies breaks login in production (works on localhost) - Better Auth
BA
Better Auth
•
3mo ago
•
3 replies
RoBoMoGoCho
crossSubDomainCookies breaks login in production (works on localhost)
Next.js
Does Better Auth have issues with crossSubDomainCookies when behind a reverse proxy
? Are there additional headers or settings needed
?
Environment
:
- Next
.js 15
(App Router
) on port 3000
- Caddy reverse proxy
(HTTPS termination
, forwards to HTTP
)
- Domain
: app
.mydomain
.com
(main
)
+
.app
.mydomain
.com
(instances
)
Server config
(auth
.ts
)
:
`
`
`
trustedOrigins
:
[
'
https://app.mydomain.com
'
,
'
h
t
t
p
s
:
/
/
.app
.mydomain
.com
'
]
,
advanced
:
{
crossSubDomainCookies
:
{
enabled
: true
,
domain
:
'app
.mydomain
.com
'
}
}
``
## Client config:
``
## Client config:
fetchOptions
:
{ credentials
:
'include
'
}
`
Symptom
:
After Google OAuth callback
, user gets redirected back to login page
. Logs show state
_mismatch error
.
What works
:
Localhost with same config
(minus HTTPS
)
. What fails
: Production behind Caddy proxy
.
Recent Announcements
Similar Threads
Does crossSubDomainCookies not work on localhost?
BA
Better Auth / help
12mo ago
crossSubDomainCookies setup
BA
Better Auth / help
5mo ago
Cookies not being set on Vercel (works on localhost)
BA
Better Auth / help
8mo ago