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