I'm looking for a way to pass common session data to store, so I thought _layout.html is the place I can use. But while session (second argument of preload) is there in browser, it's missing on server side. If it's an expected behavior, where is the proper place to fill store from session?
With PR https://github.com/sveltejs/sapper/pull/582, you don't need preload, it just works like $page and $preloaded.
import { session } from '@sapper/app'
export const userId = derive(session, session => session && session.userId)
See #593 which is aligned w/ the problem you're talking about here.
Should be fixed now.
@thgh thanks, it works :)
I'm not quite get this idea export const userId = derive(session, session => session && session.userId). How would you change userId afterwards when you do some ajax request for let's say log out? Does session meant to be changed by hands in such cases?
Yes, even though you get session from the server, that only happens on page load. After that, you gotta make sure to keep it up-to-date, that's why it's a writable store.
With PR #582, you don't need preload, it just works like $page and $preloaded.
import { session } from '@sapper/app' export const userId = derive(session, session => session && session.userId)
@thgh I'm not seeing how this works?
But, I would like something like this. I cannot figure out how to get data from the session on the start of the application. I would expect something from client.js.