Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: update next.js auth middleware example (#31035)

Joel Lee6af2bcf346b1
diff --git a/apps/docs/content/guides/auth/server-side/nextjs.mdx b/apps/docs/content/guides/auth/server-side/nextjs.mdx
index 8189371cc26..f489a5344d2 100644
--- a/apps/docs/content/guides/auth/server-side/nextjs.mdx
+++ b/apps/docs/content/guides/auth/server-side/nextjs.mdx
@@ -247,10 +247,12 @@ export async function updateSession(request: NextRequest) {
}
)
- // IMPORTANT: Avoid writing any logic between createServerClient and
+ // Do not run code between createServerClient and
// supabase.auth.getUser(). A simple mistake could make it very hard to debug
// issues with users being randomly logged out.
+ // IMPORTANT: DO NOT REMOVE auth.getUser()
+
const {
data: { user },
} = await supabase.auth.getUser()
@@ -266,8 +268,8 @@ export async function updateSession(request: NextRequest) {
return NextResponse.redirect(url)
}
- // IMPORTANT: You *must* return the supabaseResponse object as it is. If you're
- // creating a new response object with NextResponse.next() make sure to:
+ // IMPORTANT: You *must* return the supabaseResponse object as it is.
+ // If you're creating a new response object with NextResponse.next() make sure to:
// 1. Pass the request in it, like so:
// const myNewResponse = NextResponse.next({ request })
// 2. Copy over the cookies, like so: