Better Auth in production not sending cookie back

mariuzm
PRO

9 days ago

Project ID bc5c1d0e-64b7-4fe7-85bd-991ed63e5b86

Im most certain that this is not railway issue but still want to try. The current app i'm using better auth. When i try login with google i don't get cookie back

If this helps the URL domain is registered with Hostinger then via Cloudflare proxy > railway

$10 Bounty

4 Replies

mariuzm
PRO

9 days ago

One interesting part is that if i generate client url with railway and add to google credentials and better auth that URL works

but the one that is the main url does not, im not sure if this is related to cloudflare

Update:
i created api.example.com using the original domain and i think its working, so does it mean cloudflare removing cookie if server and web are not from same domain? pls could someone with more experience in this clarify this


9 days ago

I think it's more of a CORS issue or the browser enforcing some cookie rules? afaik there's a better-auth config for allowing cross sub domains cookies that may help


9 days ago

I also use better-auth on prod but all domains are directly on Railway and not through a Proxy, all SSOs work fine


mariuzm
PRO

9 days ago

interesting i think i tried a lot of things with cors but non worked, now when switched my server to be api.domain.com and update CF that solved the issue


irazvan2745
PROTop 5% Contributor

9 days ago

Do you have the better-auth env variables set? the most needed one is the Betterauth url one.

Check the network tab see where the requests are made, if its localhost then something is broken


mariuzm
PRO

9 days ago

Yep urls are set correctly.


mariuzm
PRO

9 days ago

i still think its something todo with Cloudflare and same domain stuff getting cookie


irazvan2745
PROTop 5% Contributor

8 days ago

Whats the network tab saying?


Better Auth in production not sending cookie back - Railway Help Station