houdini
houdini copied to clipboard
Ability to set the session location in setSession
Describe the feature
The new getSession function allows for extracting the session data from either local, data or the parent.
However the setSession function only allows storing in locals.
During a LayoutLoad event, it is possible to set the session in the event data as follows:
export const load: LayoutLoad = async (event) => {
const { session } = await getSupabase(event);
if (browser && session?.access_token) {
// setSession({ user: { token: session.access_token } });
event.data['__houdini__session__'] = { user: { token: session.access_token } };
}
return { session };
};
However it would be good to set this via the setSession, probably using the same logic in getSession to determine what kind of event it is
Criticality
nice to have
Oh, interesting! Do you think its safe to set it in both places always? I'm personally still a little hazy about the best way to string all of this together. What we have seems to work but I have a feeling it could be better somehow 🤔
I think the way it is now is pretty good - except what I think would be good is a way to override the default session location in order to reuse existing session state that may be stored from other libraries / approaches. I.e at the moment I am duplicating the session state in the __houdini__session__ from an existing store used by Supabase.
interface Locals {
session: import('@supabase/supabase-js').Session | null;
}
interface PageData {
session: import('@supabase/supabase-js').Session | null;
}
interface Session {
user?: {
token: string;
};
}
Sorry this went a bit stale. If you want to submit a PR that adds this configuration I'd happily review it. Maybe it makes most sense to do as a third arg to setSession?
edit: thinking about this some more it probably needs to exist as a config value so that the generated session logic can look in the right place too
I'm closing this issue since its gone a bit stale. feel free to let me know if you want to keep exploring options here