Skip to content

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

docs: nextjs missing createClient example code (#21532)

hallidayoe9763360a145
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
<StepHikeCompact.Code>
+ <CH.Code className="min-h-[34rem]">
+
```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.
+ }
+ },
+ },
+ }
+ )
+ }
+ ```
+
+ </CH.Code>
+
</StepHikeCompact.Code>
</StepHikeCompact.Step>