houdini
houdini copied to clipboard
Returning data from +layout.server.ts breaks session
Describe the bug
As soon as i load and return data in +layout.server.ts the client session breaks down. On SSR requests the authorization is still set correctly from the session, however on the client the session is empty. Once i remove +layout.server.ts the client side session works as expected. Probably related to #544
Severity
blocking an upgrade
Steps to Reproduce the Bug
- Setup Projekt
- Add login logic
- Creat button. On click load data
- Login and click button --> Session should be fine
- Add +layout.server.ts and return data
- Click button --> Session is an empty object.
Reproduction
No response
Currently you have to manually reset houdini__session in the returned data object of +layout.server.ts
export const load = async (event) => {
let session = event.locals.session.data
if(session){
const {data} = await // fetch stuff
}
return {
__houdini__session__: session,
...data
}
}
Otherwise the session will be empty on the client. I think houdini should add houdini__session to the returned data object in the background instead.
Thanks for opening this @yoh-extradat!
I think houdini should add houdini__session to the returned data object in the background instead.
I thought it was but its possible there's some issue with the implementation. I have kind of a busy day ahead of me but i'll try to find some time to look into this in the next few days if someone else doesn't get to it first
@yoh-extradat I was unable to reproduce this on the integration tests. Here is a screenshot of the different parts:

The session query just echos the value pulled out of houdini's session. This seems to work on both client side navigations and on the server.
If you have the time to hop on discord to walk through this a little closer, feel free to send me a message (i'm @AlecAivazis on the svelte discord)
I'm going to close this since I can't reproduce it. Let me know if it's still an issue and I can reopen it 👍
Sorry for the late reply! Ran into the same problem again. Both times i was using houdini in combination with Svelte Kit Cookie Session.
hooks.sverver.ts
import { handleSession } from 'svelte-kit-cookie-session';
import { sequence } from '@sveltejs/kit/hooks';
import { setSession } from '$houdini'
const sessionHandler = handleSession({
secret: 'SESSION_SECRET'
})
export const handle = sequence(sessionHandler, ({ event, resolve }) => {
setSession(event, event.locals.session.data)
return resolve(event)
})
If i am not resetting houdini__session in my +layout.server.ts queries are supported but mutations receive an empty session object.