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' ...@@ -8,6 +8,8 @@ import { cookies } from 'next/headers'
import Image from 'next/image' import Image from 'next/image'
import { redirect } from 'next/navigation' import { redirect } from 'next/navigation'
export const dynamic = 'force-dynamic'
export default async function ProtectedRoute() { export default async function ProtectedRoute() {
const supabase = createServerComponentClient({ cookies }) const supabase = createServerComponentClient({ cookies })
......
...@@ -4,6 +4,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' ...@@ -4,6 +4,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
export const dynamic = 'force-dynamic'
export async function GET() { export async function GET() {
// Create a Supabase client configured to use cookies // Create a Supabase client configured to use cookies
const supabase = createRouteHandlerClient({ cookies }) const supabase = createRouteHandlerClient({ cookies })
......
...@@ -4,6 +4,8 @@ import { createServerActionClient } from '@supabase/auth-helpers-nextjs' ...@@ -4,6 +4,8 @@ import { createServerActionClient } from '@supabase/auth-helpers-nextjs'
import { revalidatePath } from 'next/cache' import { revalidatePath } from 'next/cache'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const dynamic = 'force-dynamic'
export default async function ServerAction() { export default async function ServerAction() {
const addTodo = async (formData: FormData) => { const addTodo = async (formData: FormData) => {
'use server' 'use server'
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs' import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
export const dynamic = 'force-dynamic'
export default async function ServerComponent() { export default async function ServerComponent() {
// Create a Supabase client configured to use cookies // Create a Supabase client configured to use cookies
const supabase = createServerComponentClient({ cookies }) const supabase = createServerComponentClient({ cookies })
......
...@@ -2,6 +2,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' ...@@ -2,6 +2,8 @@ import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers' import { cookies } from 'next/headers'
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
export const dynamic = 'force-dynamic'
export async function GET(request: Request) { export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented // 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. // by the Auth Helpers package. It exchanges an auth code for the user's session.
......
...@@ -5,6 +5,8 @@ import LogoutButton from '../components/LogoutButton' ...@@ -5,6 +5,8 @@ import LogoutButton from '../components/LogoutButton'
import SupabaseLogo from '../components/SupabaseLogo' import SupabaseLogo from '../components/SupabaseLogo'
import NextJsLogo from '../components/NextJsLogo' import NextJsLogo from '../components/NextJsLogo'
export const dynamic = 'force-dynamic'
const resources = [ const resources = [
{ {
title: 'Cookie-based Auth and the Next.js App Router', title: 'Cookie-based Auth and the Next.js App Router',
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"devDependencies": { "devDependencies": {
"@types/node": "20.3.1", "@types/node": "20.3.1",
"@types/react": "18.2.12", "@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