From 0d17b6c006769c389d7f8d15397398b53441b8f8 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Thu, 24 Oct 2024 12:42:04 -0400 Subject: [PATCH] Replace example with auth in a layout --- docs/references/nextjs/auth.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/references/nextjs/auth.mdx b/docs/references/nextjs/auth.mdx index cbb08a92f9..753b935393 100644 --- a/docs/references/nextjs/auth.mdx +++ b/docs/references/nextjs/auth.mdx @@ -133,21 +133,21 @@ export async function GET() { ## Use `auth.protect()` to check if a user is authenticated -`auth.protect()` can be used in a `layout.tsx` file to protect the entire route, including all children. +`auth.protect()` can be used in a `page.tsx` file to protect any page in your application. In the following example, -- the `auth.protect()` helper is used to check if a user visiting any `/dashboard` route is authenticated. +- the `auth.protect()` helper is used to check if a user visiting the `/dashboard` route is authenticated. - If the user is not authenticated, they will be redirected to the sign-in route. -- If the user is authenticated, they can view any `/dashboard` route and its children. +- If the user is authenticated, they can view the `/dashboard` page. -```tsx {{ filename: 'app/dashboard/layout.tsx' }} +```tsx {{ filename: 'app/dashboard/page.tsx' }} import { auth } from '@clerk/nextjs/server' -export default async function Layout({ children }: { children: React.ReactNode }) { - await auth.protect() +export default async function Page() { + const { userId } = await auth.protect() - return <>{children} + return

Welcome, {userId}

} ```