-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Next.js@15 compatibility (#4366)
Co-authored-by: Bryce Kalow <[email protected]> Co-authored-by: panteliselef <[email protected]>
- Loading branch information
1 parent
8ddb3ea
commit a0204a8
Showing
80 changed files
with
3,122 additions
and
1,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/nextjs": major | ||
--- | ||
|
||
Stop `<ClerkProvider>` from opting applications into dynamic rendering. A new prop, `<ClerkProvider dynamic>` can be used to opt-in to dynamic rendering and make auth data available during server-side rendering. The RSC `auth()` helper should be preferred for accessing auth data during dynamic rendering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
"@clerk/nextjs": major | ||
"@clerk/upgrade": minor | ||
--- | ||
|
||
@clerk/nextjs: Converting auth() and clerkClient() interfaces to be async | ||
@clerk/upgrade: Adding required codemod for @clerk/nextjs breaking changes | ||
|
||
# Migration guide | ||
|
||
## `auth()` is now async | ||
|
||
Previously the `auth()` method from `@clerk/nextjs/server` was synchronous. | ||
|
||
```typescript | ||
import { auth } from '@clerk/nextjs/server'; | ||
|
||
export function GET() { | ||
const { userId } = auth(); | ||
return new Response(JSON.stringify({ userId })); | ||
} | ||
``` | ||
|
||
The `auth` method now becomes asynchronous. You will need to make the following changes to the snippet above to make it compatible. | ||
|
||
```diff | ||
- export function GET() { | ||
+ export async function GET() { | ||
- const { userId } = auth(); | ||
+ const { userId } = await auth(); | ||
return new Response(JSON.stringify({ userId })); | ||
} | ||
``` | ||
|
||
## Clerk middleware auth is now async | ||
|
||
```typescript | ||
import { clerkClient, clerkMiddleware } from '@clerk/nextjs/server'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export default clerkMiddleware(async (auth, request) => { | ||
const resolvedAuth = await auth(); | ||
|
||
const count = await resolvedAuth.users.getCount(); | ||
|
||
if (count) { | ||
return NextResponse.redirect(new URL('/new-url', request.url)); | ||
} | ||
}); | ||
|
||
export const config = { | ||
matcher: [...], | ||
}; | ||
``` | ||
|
||
## clerkClient() is now async | ||
|
||
Previously the `clerkClient()` method from `@clerk/nextjs/server` was synchronous. | ||
|
||
```typescript | ||
import { clerkClient, clerkMiddleware } from '@clerk/nextjs/server'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export default clerkMiddleware((auth, request) => { | ||
const client = clerkClient(); | ||
|
||
const count = await client.users?.getCount(); | ||
|
||
if (count) { | ||
return NextResponse.redirect(new URL('/new-url', request.url)); | ||
} | ||
}); | ||
|
||
export const config = { | ||
matcher: [...], | ||
}; | ||
``` | ||
|
||
The method now becomes async. You will need to make the following changes to the snippet above to make it compatible. | ||
|
||
```diff | ||
- export default clerkMiddleware((auth, request) => { | ||
- const client = clerkClient(); | ||
+ export default clerkMiddleware(async (auth, request) => { | ||
+ const client = await clerkClient(); | ||
const count = await client.users?.getCount(); | ||
|
||
if (count) { | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@clerk/nextjs": major | ||
--- | ||
|
||
Support `unstable_rethrow` inside `clerkMiddleware`. | ||
We changed the errors thrown by `protect()` inside `clerkMiddleware` in order for `unstable_rethrow` to recognise them and rethrow them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/nextjs": major | ||
--- | ||
|
||
Removes deprecated APIs: `authMiddleware()`, `redirectToSignIn()`, and `redirectToSignUp()`. See the migration guide to learn how to update your usage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/clerk-react": minor | ||
--- | ||
|
||
Internal changes to support `<ClerkProvider dynamic>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/api/me/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { auth } from '@clerk/nextjs/server'; | ||
|
||
export function GET() { | ||
const { userId } = auth(); | ||
export async function GET() { | ||
const { userId } = await auth(); | ||
return new Response(JSON.stringify({ userId })); | ||
} |
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/api/settings/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { auth } from '@clerk/nextjs/server'; | ||
|
||
export function GET() { | ||
const { userId } = auth().protect(has => has({ role: 'admin' }) || has({ role: 'org:editor' })); | ||
export async function GET() { | ||
const { userId } = await auth.protect((has: any) => has({ role: 'admin' }) || has({ role: 'org:editor' })); | ||
return new Response(JSON.stringify({ userId })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
integration/templates/next-app-router/src/app/only-admin/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <div>User is admin</div>; | ||
} |
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/organizations-by-id/[id]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/organizations-by-id/[id]/settings/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/organizations-by-slug/[slug]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/organizations-by-slug/[slug]/settings/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
integration/templates/next-app-router/src/app/page-protected/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { auth } from '@clerk/nextjs/server'; | ||
|
||
export default function Page() { | ||
auth().protect(); | ||
export default async function Page() { | ||
await auth.protect(); | ||
|
||
return <div>Protected Page</div>; | ||
} |
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/personal-account/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/settings/auth-has/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration/templates/next-app-router/src/app/settings/auth-protect/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { auth } from '@clerk/nextjs/server'; | ||
|
||
export default function Page() { | ||
auth().protect({ role: 'admin' }); | ||
export default async function Page() { | ||
await auth.protect({ role: 'admin' }); | ||
return <p>User has access</p>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.