diff --git a/examples/with-supabase/app/auth/callback/route.ts b/examples/with-supabase/app/auth/callback/route.ts index ae5504eaed27d..3822631953d96 100644 --- a/examples/with-supabase/app/auth/callback/route.ts +++ b/examples/with-supabase/app/auth/callback/route.ts @@ -1,7 +1,6 @@ import { createClient } from '@/utils/supabase/server' import { NextResponse } from 'next/server' - -export const dynamic = 'force-dynamic' +import { cookies } from 'next/headers' export async function GET(request: Request) { // The `/auth/callback` route is required for the server-side auth flow implemented @@ -11,7 +10,8 @@ export async function GET(request: Request) { const code = requestUrl.searchParams.get('code') if (code) { - const supabase = createClient() + const cookieStore = cookies() + const supabase = createClient(cookieStore) await supabase.auth.exchangeCodeForSession(code) } diff --git a/examples/with-supabase/app/auth/sign-in/route.ts b/examples/with-supabase/app/auth/sign-in/route.ts index f13d0726930ea..42f7318234334 100644 --- a/examples/with-supabase/app/auth/sign-in/route.ts +++ b/examples/with-supabase/app/auth/sign-in/route.ts @@ -1,14 +1,14 @@ import { createClient } from '@/utils/supabase/server' import { NextResponse } from 'next/server' - -export const dynamic = 'force-dynamic' +import { cookies } from 'next/headers' export async function POST(request: Request) { const requestUrl = new URL(request.url) const formData = await request.formData() const email = String(formData.get('email')) const password = String(formData.get('password')) - const supabase = createClient() + const cookieStore = cookies() + const supabase = createClient(cookieStore) const { error } = await supabase.auth.signInWithPassword({ email, diff --git a/examples/with-supabase/app/auth/sign-out/route.ts b/examples/with-supabase/app/auth/sign-out/route.ts index be19b57362003..ebff54a457ff3 100644 --- a/examples/with-supabase/app/auth/sign-out/route.ts +++ b/examples/with-supabase/app/auth/sign-out/route.ts @@ -1,11 +1,11 @@ import { createClient } from '@/utils/supabase/server' import { NextResponse } from 'next/server' - -export const dynamic = 'force-dynamic' +import { cookies } from 'next/headers' export async function POST(request: Request) { const requestUrl = new URL(request.url) - const supabase = createClient() + const cookieStore = cookies() + const supabase = createClient(cookieStore) await supabase.auth.signOut() diff --git a/examples/with-supabase/app/auth/sign-up/route.ts b/examples/with-supabase/app/auth/sign-up/route.ts index c9d020c99ea9f..f70136faa6081 100644 --- a/examples/with-supabase/app/auth/sign-up/route.ts +++ b/examples/with-supabase/app/auth/sign-up/route.ts @@ -1,14 +1,14 @@ import { createClient } from '@/utils/supabase/server' import { NextResponse } from 'next/server' - -export const dynamic = 'force-dynamic' +import { cookies } from 'next/headers' export async function POST(request: Request) { const requestUrl = new URL(request.url) const formData = await request.formData() const email = String(formData.get('email')) const password = String(formData.get('password')) - const supabase = createClient() + const cookieStore = cookies() + const supabase = createClient(cookieStore) const { error } = await supabase.auth.signUp({ email, diff --git a/examples/with-supabase/app/page.tsx b/examples/with-supabase/app/page.tsx index 12b3a3cb89d98..683abf91d0eaf 100644 --- a/examples/with-supabase/app/page.tsx +++ b/examples/with-supabase/app/page.tsx @@ -4,19 +4,20 @@ import { createClient } from '@/utils/supabase/server' import ConnectSupabaseSteps from '@/components/ConnectSupabaseSteps' import SignUpUserSteps from '@/components/SignUpUserSteps' import Header from '@/components/Header' +import { cookies } from 'next/headers' -export const dynamic = 'force-dynamic' +export default async function Index() { + const cookieStore = cookies() -const canInitSupabaseClient = () => { - try { - createClient() - return true - } catch (e) { - return false + const canInitSupabaseClient = () => { + try { + createClient(cookieStore) + return true + } catch (e) { + return false + } } -} -export default async function Index() { const isSupabaseConnected = canInitSupabaseClient() return ( diff --git a/examples/with-supabase/components/AuthButton.tsx b/examples/with-supabase/components/AuthButton.tsx index a08d8a6ef131d..f9e2b3a54dae3 100644 --- a/examples/with-supabase/components/AuthButton.tsx +++ b/examples/with-supabase/components/AuthButton.tsx @@ -1,8 +1,10 @@ import { createClient } from '@/utils/supabase/server' import Link from 'next/link' +import { cookies } from 'next/headers' export default async function AuthButton() { - const supabase = createClient() + const cookieStore = cookies() + const supabase = createClient(cookieStore) const { data: { user }, diff --git a/examples/with-supabase/utils/supabase/server.ts b/examples/with-supabase/utils/supabase/server.ts index 2fbf5bfc75c07..8dbd681fdb974 100644 --- a/examples/with-supabase/utils/supabase/server.ts +++ b/examples/with-supabase/utils/supabase/server.ts @@ -1,9 +1,7 @@ import { createServerClient, type CookieOptions } from '@supabase/ssr' import { cookies } from 'next/headers' -export const createClient = () => { - const cookieStore = cookies() - +export const createClient = (cookieStore: ReturnType) => { return createServerClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,