Search
Star
Feedback
Setup for Free
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
crossSubDomainCookies breaks login in production (works on localhost) - Better Auth
BA
Better Auth
•
4w 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
.
Better Auth
Join
9,988
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
Does crossSubDomainCookies not work on localhost?
BA
Better Auth / help
10mo ago
Use production auth on localhost & previews
BA
Better Auth / help
2mo ago
crossSubDomainCookies setup
BA
Better Auth / help
3mo ago
Cookies not being set on Vercel (works on localhost)
BA
Better Auth / help
6mo ago