Svelte Kit hooks.server.ts getSession not working
I want to use better-auth with SvelteKit, but I don't use the
svelteKitHandler
.. I've set-up a custom route apps/frontend/src/routes/api/auth/[...all]/+server.ts
with the following code:
This is because it uses two Cloudflare Workers, one running the server and the other just a proxy.
Now i want to use inside hooks.server.ts
the following code
The cookie inside event.request.headers
does include the etter-auth.session_token=
, but it still always return null
.. I can't use auth.api.getSession
because the auth instance runs in a different worker, but according to the docs it should work with https://www.better-auth.com/docs/reference/faq
I think I'm maybe missing some setup, which is needed if I use a custom api route and note the svelteKitHandler
, but I'm a bit lost. Can anyone help?2 Replies
Calling the proxy route with fetch directly, works and returns the session 🤔
I'm lost why it doesn't work with the
authClient
This will work fine