houdini icon indicating copy to clipboard operation
houdini copied to clipboard

Returning data from +layout.server.ts breaks session

Open yoh-extradat opened this issue 3 years ago • 3 comments

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

  1. Setup Projekt
  2. Add login logic
  3. Creat button. On click load data
  4. Login and click button --> Session should be fine
  5. Add +layout.server.ts and return data
  6. Click button --> Session is an empty object.

Reproduction

No response

yoh-extradat avatar Sep 18 '22 13:09 yoh-extradat

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.

yoh-extradat avatar Sep 18 '22 14:09 yoh-extradat

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

AlecAivazis avatar Sep 18 '22 19:09 AlecAivazis

@yoh-extradat I was unable to reproduce this on the integration tests. Here is a screenshot of the different parts: image

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)

AlecAivazis avatar Sep 19 '22 18:09 AlecAivazis

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 👍

AlecAivazis avatar Oct 10 '22 15:10 AlecAivazis

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.

yoh-extradat avatar Dec 08 '22 15:12 yoh-extradat