Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Call cookies function from route to flag as dynamic #57494

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/with-supabase/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/with-supabase/app/auth/sign-in/route.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/with-supabase/app/auth/sign-out/route.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
6 changes: 3 additions & 3 deletions examples/with-supabase/app/auth/sign-up/route.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
19 changes: 10 additions & 9 deletions examples/with-supabase/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 3 additions & 1 deletion examples/with-supabase/components/AuthButton.tsx
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
4 changes: 1 addition & 3 deletions examples/with-supabase/utils/supabase/server.ts
Original file line number Diff line number Diff line change
@@ -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<typeof cookies>) => {
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
Expand Down
Loading