From e9763360a145d50f77ffe54ee4dd5f3af21fdd41 Mon Sep 17 00:00:00 2001 From: hallidayo <22655069+Hallidayo@users.noreply.github.com> Date: Tue, 5 Mar 2024 05:49:38 +0000 Subject: [PATCH] docs: nextjs missing createClient example code (#21532) added createClient function example Co-authored-by: Chris Gwilliams <517923+encima@users.noreply.github.com> --- .../getting-started/quickstarts/nextjs.mdx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx b/apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx index 0568426c37e..65ab0d417e3 100644 --- a/apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx +++ b/apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx @@ -92,6 +92,8 @@ hideToc: true + + ```ts app/notes/page.tsx import { createClient } from '@/utils/supabase/server'; @@ -103,6 +105,47 @@ hideToc: true } ``` + ```ts utils/supabase/server.ts + import { createServerClient, type CookieOptions } from '@supabase/ssr' + import { cookies } from 'next/headers' + + export function createClient() { + const cookieStore = cookies() + + return createServerClient( + process.env.NEXT_PUBLIC_SUPABASE_URL!, + process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, + { + cookies: { + get(name: string) { + return cookieStore.get(name)?.value + }, + set(name: string, value: string, options: CookieOptions) { + try { + cookieStore.set({ name, value, ...options }) + } catch (error) { + // The `set` method was called from a Server Component. + // This can be ignored if you have middleware refreshing + // user sessions. + } + }, + remove(name: string, options: CookieOptions) { + try { + cookieStore.set({ name, value: '', ...options }) + } catch (error) { + // The `delete` method was called from a Server Component. + // This can be ignored if you have middleware refreshing + // user sessions. + } + }, + }, + } + ) + } + ``` + + +