Setting up a project with SvelteKit Session Cookie and Houdini i ran into some problems and it took me a while to find a working setup.
If is setup +layout.svelte.ts as recommended:
/** @type {import('./$types').LayoutServerLoad} */
export const load = ({ locals }) => {
return {
session: locals.session.data // You can also use your old `getSession` function if you wish.
};
};
The houdini client receives an empty session object.
In order to solve this, I have to extent hooks.server.ts
import { handleSession } from 'svelte-kit-cookie-session';
import { sequence } from '@sveltejs/kit/hooks';
import { setSession } from '$houdini'
const sessionHandler = handleSession({
secret: 'YOUR_SECRET_KEY'
})
export const handle = sequence(sessionHandler, ({ event, resolve }) => {
setSession(event, event.locals.session.data) //otherwise houdini will not get the session
return resolve(event)
})
Now queries work, but for mutations the client is still receiving empty session objects.
To fix this i have to manually reset houdinisession in +layout.server.ts:
Setting up a project with SvelteKit Session Cookie and Houdini i ran into some problems and it took me a while to find a working setup.
If is setup +layout.svelte.ts as recommended:
The houdini client receives an empty session object. In order to solve this, I have to extent hooks.server.ts
Now queries work, but for mutations the client is still receiving empty session objects. To fix this i have to manually reset houdinisession in +layout.server.ts:
Any ideas why the recommended implementation isn't working!?