Skip to content

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

Fix nextjs example in ssr docs (#27622)

Erik Petersen9a18d013c29b
diff --git a/apps/docs/content/guides/auth/server-side/nextjs.mdx b/apps/docs/content/guides/auth/server-side/nextjs.mdx
index 8663a5f0eab..2925dab980d 100644
--- a/apps/docs/content/guides/auth/server-side/nextjs.mdx
+++ b/apps/docs/content/guides/auth/server-side/nextjs.mdx
@@ -243,11 +243,15 @@ export async function updateSession(request: NextRequest) {
// supabase.auth.getUser(). A simple mistake could make it very hard to debug
// issues with users being randomly logged out.
- const { data: user, error } = await supabase.auth.getUser()
+ const {
+ data: { user },
+ } = await supabase.auth.getUser()
- if (!user) {
+ if (!user && !request.nextUrl.pathname.startsWith('/login')) {
// no user, potentially respond by redirecting the user to the login page
- return NextResponse.redirect('/login')
+ const url = request.nextUrl.clone()
+ url.pathname = '/login'
+ return NextResponse.redirect(url)
}
// IMPORTANT: You *must* return the supabaseResponse object as it is. If you're