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:
import type { RequestHandler } from "./$types";

// const ORPC_ENDPOINT = import.meta.env.VITE_ORPC_ENDPOINT

export const fallback: RequestHandler = async ({ request, platform }) => {
  console.log("Fallback handler called for:", request.url);
  // if (import.meta.env.DEV) {
  //   return await fetch(`${ORPC_ENDPOINT}${new URL(request.url).pathname}`, request)
  // } else {
  const t = await platform!.env.ORM.fetch(`http://localhost:8210${new URL(request.url).pathname}`, request)

  return new Response(t.body, {
    status: t.status,
    statusText: t.statusText,
    headers: t.headers,
  });
};


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
const addGraphQLClient: Handle = async ({ event, resolve }) => {
  const { data: session } = await authClient.getSession({
    query: {
      disableCookieCache: true,
      disableRefresh: false
    },
    fetchOptions: {
      headers: event.request.headers
    }
  });
}


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?
Was this page helpful?