session data is null despite session cookie
so i have a hono api and i've writtten a custom middlware to check for authentication which works fine locally however, in prod (deployed on cf workers) despite the headers containing the session cookie the session is null, here's my middleware: https://github.com/777advait/better-auth-monorepo/blob/main/apps/api/src/middlewares/authenticated.ts
server logs:
this works perfectly fine locally (both in bun and wrangler runtime) so is it an issue with cf workers?
GitHub
better-auth-monorepo/apps/api/src/middlewares/authenticated.ts at m...
Contribute to 777advait/better-auth-monorepo development by creating an account on GitHub.
Solution:Jump to solution
i fixed it! it was a cloudflare issue, i was instantiating an auth instance in my api app, and the base URL of that was a worker, workers dont allow communication among each other over public network, the requests fail silently (no messages no warnings), it can only be permitted via service bindings
https://developers.cloudflare.com/workers/configuration/routing/custom-domains/#worker-to-worker-communication
https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/
i just moved my auth stuff into the api app so there's no worker-worker communication, everything sits in one place, it'd be good to be able to define custom fetch functions when instantiating auth instances in future...
Cloudflare Docs
Custom Domains
Custom Domains allow you to connect your Worker to a domain or subdomain, without having to make changes to your DNS settings or perform any certificate management. After you set up a Custom Domain for your Worker, Cloudflare will create DNS records and issue necessary certificates on your behalf. The created DNS records will point directly to y...
1 Reply
Solution
i fixed it! it was a cloudflare issue, i was instantiating an auth instance in my api app, and the base URL of that was a worker, workers dont allow communication among each other over public network, the requests fail silently (no messages no warnings), it can only be permitted via service bindings
https://developers.cloudflare.com/workers/configuration/routing/custom-domains/#worker-to-worker-communication
https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/
i just moved my auth stuff into the api app so there's no worker-worker communication, everything sits in one place, it'd be good to be able to define custom fetch functions when instantiating auth instances in future
Cloudflare Docs
Custom Domains
Custom Domains allow you to connect your Worker to a domain or subdomain, without having to make changes to your DNS settings or perform any certificate management. After you set up a Custom Domain for your Worker, Cloudflare will create DNS records and issue necessary certificates on your behalf. The created DNS records will point directly to y...