Better Auth in production not sending cookie back
mariuzm
PROOP

6 months 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

8 Replies

mariuzm
PROOP

6 months 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


6 months 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


6 months 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
PROOP

6 months 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
FREE

6 months 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
PROOP

6 months ago

Yep urls are set correctly.


mariuzm
PROOP

6 months ago

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


irazvan2745
FREE

6 months ago

Whats the network tab saying?


Loading...