diff --git a/apps/docs/pages/guides/auth/server-side/creating-a-client.mdx b/apps/docs/pages/guides/auth/server-side/creating-a-client.mdx index b236ef0adb0..a2ca9e9b1d1 100644 --- a/apps/docs/pages/guides/auth/server-side/creating-a-client.mdx +++ b/apps/docs/pages/guides/auth/server-side/creating-a-client.mdx @@ -467,7 +467,7 @@ export const handle: Handle = async ({ event, resolve }) => { - + @@ -478,7 +478,7 @@ Page components can get access to the supabase client from the `data` object due ```ts +layout.ts import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public' import type { LayoutLoad } from './$types' -import { createBrowserClient, isBrowser, parse } from '@supabase/ssr' +import { combineChunks, createBrowserClient, isBrowser, parse } from '@supabase/ssr' export const load: LayoutLoad = async ({ fetch, data, depends }) => { depends('supabase:auth') @@ -493,8 +493,11 @@ export const load: LayoutLoad = async ({ fetch, data, depends }) => { return JSON.stringify(data.session) } - const cookie = parse(document.cookie) - return cookie[key] + const cookie = combineChunks(key, (name) => { + const cookies = parse(document.cookie) + return cookies[name] + }) + return cookie }, }, }) @@ -509,6 +512,20 @@ export const load: LayoutLoad = async ({ fetch, data, depends }) => { + + +```ts +layout.server.ts +import type { LayoutServerLoad } from './$types' + +export const load: LayoutServerLoad = async ({ locals: { getSession } }) => { + return { + session: await getSession(), + } +} +``` + + + ```svelte +page.svelte