Unverified Commit 2b497413 authored by Jon Meyers's avatar Jon Meyers Committed by GitHub

examples: export `force-dynamic` from all dynamic routes (#52916)

### What?

Stop `with-supabase` template from throwing errors on build

### Why?

Dynamic Routes now fail the build, rather than console.logging an error

### How?

Export the following from any routes that use the `cookies` function

```
export const dynamic = "force-dynamic";
```

Install `encoding` as a dev dependency until this is fixed downstream
parent 66f0983c
......@@ -8,6 +8,8 @@ import { cookies } from 'next/headers'
import Image from 'next/image'
import { redirect } from 'next/navigation'
export const dynamic = 'force-dynamic'
export default async function ProtectedRoute() {
const supabase = createServerComponentClient({ cookies })
......
......@@ -4,6 +4,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
export const dynamic = 'force-dynamic'
export async function GET() {
// Create a Supabase client configured to use cookies
const supabase = createRouteHandlerClient({ cookies })
......
......@@ -4,6 +4,8 @@ import { createServerActionClient } from '@supabase/auth-helpers-nextjs'
import { revalidatePath } from 'next/cache'
import { cookies } from 'next/headers'
export const dynamic = 'force-dynamic'
export default async function ServerAction() {
const addTodo = async (formData: FormData) => {
'use server'
......
......@@ -3,6 +3,8 @@
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
export const dynamic = 'force-dynamic'
export default async function ServerComponent() {
// Create a Supabase client configured to use cookies
const supabase = createServerComponentClient({ cookies })
......
......@@ -2,6 +2,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
export const dynamic = 'force-dynamic'
export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented
// by the Auth Helpers package. It exchanges an auth code for the user's session.
......
......@@ -5,6 +5,8 @@ import LogoutButton from '../components/LogoutButton'
import SupabaseLogo from '../components/SupabaseLogo'
import NextJsLogo from '../components/NextJsLogo'
export const dynamic = 'force-dynamic'
const resources = [
{
title: 'Cookie-based Auth and the Next.js App Router',
......
......@@ -19,6 +19,7 @@
"devDependencies": {
"@types/node": "20.3.1",
"@types/react": "18.2.12",
"@types/react-dom": "18.2.5"
"@types/react-dom": "18.2.5",
"encoding": "^0.1.13"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment