Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(sveltekit ssr docs): createBrowserClient use (#26872)

Charis4c9c96a159e5
diff --git a/apps/docs/content/guides/auth/server-side/creating-a-client.mdx b/apps/docs/content/guides/auth/server-side/creating-a-client.mdx
index a9e46b9e218..b213d2cae37 100644
--- a/apps/docs/content/guides/auth/server-side/creating-a-client.mdx
+++ b/apps/docs/content/guides/auth/server-side/creating-a-client.mdx
@@ -514,26 +514,33 @@ 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 { createBrowserClient, createServerClient, isBrowser, parse } from '@supabase/ssr'
export const load: LayoutLoad = async ({ fetch, data, depends }) => {
depends('supabase:auth')
- const supabase = createBrowserClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
- global: {
- fetch,
- },
- cookies: {
- get(key) {
- if (!isBrowser()) {
- return JSON.stringify(data.session)
- }
-
- const cookie = parse(document.cookie)
- return cookie[key]
- },
- },
- })
+ const supabase = isBrowser()
+ ? createBrowserClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
+ global: {
+ fetch,
+ },
+ cookies: {
+ get(key) {
+ const cookie = parse(document.cookie)
+ return cookie[key]
+ },
+ },
+ })
+ : createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
+ global: {
+ fetch,
+ },
+ cookies: {
+ get() {
+ return JSON.stringify(data.session)
+ },
+ },
+ })
/**
* It's fine to use `getSession` here, because on the client, `getSession` is