Skip to content

Commit da897a6

Browse files
Update nextjs.mdx (#945)
Co-authored-by: Shaquil Hansford <[email protected]>
1 parent 2f21221 commit da897a6

File tree

1 file changed

+9
-49
lines changed

1 file changed

+9
-49
lines changed

docs/quickstarts/nextjs.mdx

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -78,54 +78,10 @@ The final result should resemble the following:
7878

7979
</InjectKeys>
8080

81-
### Add `<ClerkProvider>` to your app
82-
83-
All Clerk hooks and components must be children of the [`<ClerkProvider>`](/docs/components/clerk-provider) component, which provides active session and user context.
84-
85-
Select your preferred router to learn how to make this data available across your entire app:
86-
87-
<Tabs type="router" items={["App Router", "Pages Router"]}>
88-
<Tab>
89-
```tsx filename="app/layout.tsx" {1,10-14}
90-
import { ClerkProvider } from '@clerk/nextjs'
91-
import './globals.css'
92-
93-
export default function RootLayout({
94-
children,
95-
}: {
96-
children: React.ReactNode
97-
}) {
98-
return (
99-
<ClerkProvider>
100-
<html lang="en">
101-
<body>{children}</body>
102-
</html>
103-
</ClerkProvider>
104-
)
105-
}
106-
```
107-
</Tab>
108-
109-
<Tab>
110-
```tsx filename="pages/_app.tsx" {2,6-8}
111-
import '@/styles/globals.css'
112-
import { ClerkProvider } from "@clerk/nextjs/server";
113-
import type { AppProps } from "next/app";
114-
function MyApp({ Component, pageProps }: AppProps) {
115-
return (
116-
<ClerkProvider {...pageProps}>
117-
<Component {...pageProps} />
118-
</ClerkProvider>
119-
);
120-
}
121-
export default MyApp;
122-
```
123-
</Tab>
124-
</Tabs>
125-
12681
### Add Middleware to your application
12782

128-
`clerkMiddleware()` grants you access to user authentication state throughout your application, on any route or page. It also allows you to protect specific routes from unauthenticated users. To add `clerkMiddleware()` to your application, follow these steps:
83+
[`clerkMiddleware()`](/docs/references/nextjs/clerk-middleware#clerk-middleware) grants you access to user authentication state throughout your application, on any route or page. It also allows you to protect specific routes from unauthenticated users. To add `clerkMiddleware()` to your application, follow these steps:
84+
12985

13086
1. Create a `middleware.ts` file. Your `middleware.ts` file should be placed inside the root directory alongside `.env.local`, or inside the `src/` directory if you are using it.
13187
2. In your middleware.ts, export Clerk's `clerkMiddleware()` helper:
@@ -140,7 +96,9 @@ Select your preferred router to learn how to make this data available across you
14096
```
14197
3. By default, `clerkMiddleware()` will not protect any routes. All routes are public and you must opt-in to protection for routes. See the [`clerkMiddleware()` reference](/docs/references/nextjs/clerk-middleware) to learn how to require authentication for specific routes.
14298

143-
### Create a header with Clerk components
99+
### Add `<ClerkProvider>` and components to your app
100+
101+
All Clerk hooks and components must be children of the [`<ClerkProvider>`](/docs/components/clerk-provider) component, which provides active session and user context.
144102

145103
You can control which content signed in and signed out users can see with Clerk's [prebuilt components](/docs/components/overview). To get started, create a header for your users to sign in or out. To do this, you will use:
146104

@@ -149,8 +107,10 @@ You can control which content signed in and signed out users can see with Clerk'
149107
- [`<UserButton />`](/docs/components/user/user-button): A prebuilt component that comes styled out of the box to show the avatar from the account the user is signed in with.
150108
- [`<SignInButton />`](/docs/components/unstyled/sign-in-button): An unstyled component that links to the sign-in page or displays the sign-in modal.
151109

110+
Select your preferred router to learn how to make this data available across your entire app:
111+
152112
<CodeBlockTabs type="router" options={["App Router", "Pages Router"]}>
153-
```tsx filename="app/layout.tsx" {13-20}
113+
```tsx filename="app/layout.tsx" {10,13-20}
154114
import { ClerkProvider, SignInButton, SignedIn, SignedOut, UserButton } from '@clerk/nextjs'
155115
import './globals.css';
156116

@@ -180,7 +140,7 @@ export default function RootLayout({
180140
)
181141
}
182142
```
183-
```tsx filename="pages/_app.tsx" {8-15}
143+
```tsx filename="pages/_app.tsx" {7-15}
184144
import '@/styles/globals.css'
185145
import { ClerkProvider, SignInButton, SignedIn, SignedOut, UserButton } from '@clerk/nextjs'
186146
import type { AppProps } from 'next/app'

0 commit comments

Comments
 (0)