Skip to content

Commit

Permalink
examples: export force-dynamic from all dynamic routes (#52916)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
dijonmusters committed Jul 20, 2023
1 parent 66f0983 commit 2b49741
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/with-supabase/app/_examples/protected-route/page.tsx
Expand Up @@ -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 })

Expand Down
2 changes: 2 additions & 0 deletions examples/with-supabase/app/_examples/route-handler/route.ts
Expand Up @@ -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 })
Expand Down
2 changes: 2 additions & 0 deletions examples/with-supabase/app/_examples/server-action/page.tsx
Expand Up @@ -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'
Expand Down
Expand Up @@ -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 })
Expand Down
2 changes: 2 additions & 0 deletions examples/with-supabase/app/auth/callback/route.ts
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions examples/with-supabase/app/page.tsx
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion examples/with-supabase/package.json
Expand Up @@ -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"
}
}

0 comments on commit 2b49741

Please sign in to comment.