Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SvelteKit Session Cookie and Houdini #48

Closed
yoh-extradat opened this issue Dec 8, 2022 · 1 comment
Closed

SvelteKit Session Cookie and Houdini #48

yoh-extradat opened this issue Dec 8, 2022 · 1 comment

Comments

@yoh-extradat
Copy link

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 __houdini__session in +layout.server.ts:

import { GQL_ActiveDonation } from "$houdini";
/** @type {import('./$types').LayoutServerLoad} */
export const load = async (event) => {
    const session = event.locals.session.data || null
        return {
            session: session,
            __houdini__session__: session
        }
    }
};

Any ideas why the recommended implementation isn't working!?

@pixelmund
Copy link
Owner

Hey, i'm currently trying to create a reproduction but getting blocked by #751.

I'll let you know when i find anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants