Skip to content

Commit

Permalink
Replace example with auth in a layout
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Oct 24, 2024
1 parent e1081c6 commit 0037a16
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/references/nextjs/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ 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,

Expand All @@ -144,10 +144,10 @@ In the following example,
```tsx {{ filename: 'app/dashboard/layout.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 <h1>Welcome, {userId}</h1>
}
```

Expand Down

0 comments on commit 0037a16

Please sign in to comment.