Better auth / Sveltekit user session doesn't work

Hello,
First of all, I thank the people who will help me to make Better Auth work with Svelte/kit.

For a few days, I have been trying to set up authentication using Sveltekit's SSR. For the moment, I have managed to make the signup page, I have a new user in my PostgreSQL database. When I try to connect, I get the user information, but I do not have a session at the end of the connection. (session or user undefined)

Here is the code that was set up:

+hooks.server.ts

const handleParaglide: Handle = i18n.handle();

const authHandle: Handle = async ({ event, resolve }) => {
    const session = await authClient.useSession();

    event.locals.session = session?.session;
    event.locals.user = session?.user;

    return svelteKitHandler({
        event,
        resolve,
        auth
    });
};

export const handle = sequence(authHandle, handleParaglide);
Was this page helpful?