Skip to content

Commit

Permalink
chore(nextjs)!: Remove deprecated nextjs APIs (#4356)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacek Radko <[email protected]>
  • Loading branch information
BRKalow and jacekradko authored Oct 22, 2024
1 parent b11c444 commit 1b32955
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 1,313 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-worms-report.md
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.
27 changes: 16 additions & 11 deletions integration/tests/handshake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ test.describe('Client handshake @generic', () => {
.clone()
.addFile(
'src/middleware.ts',
() => `import { authMiddleware } from '@clerk/nextjs/server';
// Set the paths that don't require the user to be signed in
const publicPaths = ['/', /^(\\/(sign-in|sign-up|app-dir|custom)\\/*).*$/];
() => `import { clerkMiddleware } from '@clerk/nextjs/server';
export const middleware = (req, evt) => {
return authMiddleware({
publicRoutes: publicPaths,
return clerkMiddleware({
publishableKey: req.headers.get("x-publishable-key"),
secretKey: req.headers.get("x-secret-key"),
proxyUrl: req.headers.get("x-proxy-url"),
Expand Down Expand Up @@ -1256,6 +1252,12 @@ test.describe('Client handshake with organization activation @nextjs', () => {
redirect: 'manual',
});

if (testCase.name === 'Header-based auth should not handshake with expired auth') {
console.log(testCase.name);
console.log(res.headers.get('x-clerk-auth-status'));
console.log(res.headers.get('x-clerk-auth-reason'));
}

expect(res.status).toBe(testCase.then.expectStatus);
const redirectSearchParams = new URLSearchParams(res.headers.get('location'));
expect(redirectSearchParams.get('organization_id')).toBe(testCase.then.fapiOrganizationIdParamValue);
Expand Down Expand Up @@ -1373,14 +1375,17 @@ test.describe('Client handshake with an organization activation avoids infinite
*/
const startAppWithOrganizationSyncOptions = async (clerkAPIUrl: string): Promise<Application> => {
const env = appConfigs.envs.withEmailCodes.clone().setEnvVariable('private', 'CLERK_API_URL', clerkAPIUrl);
const middlewareFile = `import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
const isProtectedRoute = createRouteMatcher(['/organizations(.*)'])
const middlewareFile = `import { authMiddleware } from '@clerk/nextjs/server';
// Set the paths that don't require the user to be signed in
const publicPaths = ['/', /^(\\/(sign-in|sign-up|app-dir|custom)\\/*).*$/];
export const middleware = (req, evt) => {
const orgSyncOptions = req.headers.get("x-organization-sync-options")
return authMiddleware({
publicRoutes: publicPaths,
return clerkMiddleware((auth, req) => {
if (isProtectedRoute(req) && !auth().userId) {
auth().redirectToSignIn()
}
}, {
publishableKey: req.headers.get("x-publishable-key"),
secretKey: req.headers.get("x-secret-key"),
proxyUrl: req.headers.get("x-proxy-url"),
Expand Down
119 changes: 0 additions & 119 deletions integration/tests/next-middleware.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
exports[`/server public exports should not include a breaking change 1`] = `
[
"auth",
"authMiddleware",
"buildClerkProps",
"clerkClient",
"clerkMiddleware",
"createClerkClient",
"createRouteMatcher",
"currentUser",
"getAuth",
"redirectToSignIn",
"redirectToSignUp",
"verifyToken",
]
`;
Loading

0 comments on commit 1b32955

Please sign in to comment.