From 2b497413087c56dedb3e04f77ea0deebb5d12d0b Mon Sep 17 00:00:00 2001
From: Jon Meyers <jonathon.d.meyers@gmail.com>
Date: Thu, 20 Jul 2023 23:33:43 +1000
Subject: [PATCH] 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
---
 examples/with-supabase/app/_examples/protected-route/page.tsx  | 2 ++
 examples/with-supabase/app/_examples/route-handler/route.ts    | 2 ++
 examples/with-supabase/app/_examples/server-action/page.tsx    | 2 ++
 examples/with-supabase/app/_examples/server-component/page.tsx | 2 ++
 examples/with-supabase/app/auth/callback/route.ts              | 2 ++
 examples/with-supabase/app/page.tsx                            | 2 ++
 examples/with-supabase/package.json                            | 3 ++-
 7 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/examples/with-supabase/app/_examples/protected-route/page.tsx b/examples/with-supabase/app/_examples/protected-route/page.tsx
index 97d252b29a9d3..b3df6cf820f1a 100644
--- a/examples/with-supabase/app/_examples/protected-route/page.tsx
+++ b/examples/with-supabase/app/_examples/protected-route/page.tsx
@@ -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 })
 
diff --git a/examples/with-supabase/app/_examples/route-handler/route.ts b/examples/with-supabase/app/_examples/route-handler/route.ts
index 9709709aca509..7e654a04bc512 100644
--- a/examples/with-supabase/app/_examples/route-handler/route.ts
+++ b/examples/with-supabase/app/_examples/route-handler/route.ts
@@ -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 })
diff --git a/examples/with-supabase/app/_examples/server-action/page.tsx b/examples/with-supabase/app/_examples/server-action/page.tsx
index 4807e3e8d77cf..de7443c67749f 100644
--- a/examples/with-supabase/app/_examples/server-action/page.tsx
+++ b/examples/with-supabase/app/_examples/server-action/page.tsx
@@ -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'
diff --git a/examples/with-supabase/app/_examples/server-component/page.tsx b/examples/with-supabase/app/_examples/server-component/page.tsx
index 3a82ced6a1bd6..149c4de24e07e 100644
--- a/examples/with-supabase/app/_examples/server-component/page.tsx
+++ b/examples/with-supabase/app/_examples/server-component/page.tsx
@@ -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 })
diff --git a/examples/with-supabase/app/auth/callback/route.ts b/examples/with-supabase/app/auth/callback/route.ts
index dbb00609f69f6..673099290c21b 100644
--- a/examples/with-supabase/app/auth/callback/route.ts
+++ b/examples/with-supabase/app/auth/callback/route.ts
@@ -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.
diff --git a/examples/with-supabase/app/page.tsx b/examples/with-supabase/app/page.tsx
index 472c5ce87482f..acf064173665b 100644
--- a/examples/with-supabase/app/page.tsx
+++ b/examples/with-supabase/app/page.tsx
@@ -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',
diff --git a/examples/with-supabase/package.json b/examples/with-supabase/package.json
index 750ea08a6c6c3..6ac8d3142b0b9 100644
--- a/examples/with-supabase/package.json
+++ b/examples/with-supabase/package.json
@@ -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"
   }
 }