Skip to content

Commit

Permalink
fix(nextjs): Ensure package works with next 12 (#2652)
Browse files Browse the repository at this point in the history
* fix(nextjs): Ensure packages work with next 12

* chore(repo): Add changeset
  • Loading branch information
brkalow authored Jan 23, 2024
1 parent 0ca810d commit bf7e647
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-bugs-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Adjust how we are importing `next/navigation` to ensure it can function in versions of next that don't have this export.
6 changes: 4 additions & 2 deletions packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
CheckAuthorizationParamsWithCustomPermissions,
CheckAuthorizationWithCustomPermissions,
} from '@clerk/types';
import { notFound, redirect } from 'next/navigation';

import { buildClerkProps } from '../../server/buildClerkProps';
import { createGetAuth } from '../../server/createGetAuth';
Expand Down Expand Up @@ -52,6 +51,9 @@ export const auth = () => {
noAuthStatusMessage: authAuthHeaderMissing(),
})(buildRequestLike());

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { notFound, redirect } = require('next/navigation');

(authObject as unknown as ProtectGeneric).protect = (params: any, options: any) => {
const paramsOrFunction = params?.redirectUrl
? undefined
Expand All @@ -60,7 +62,7 @@ export const auth = () => {
| ((has: CheckAuthorizationWithCustomPermissions) => boolean));
const redirectUrl = (params?.redirectUrl || options?.redirectUrl) as string | undefined;

const handleUnauthorized = (): never => {
const handleUnauthorized = (): any => {
if (redirectUrl) {
redirect(redirectUrl);
}
Expand Down

0 comments on commit bf7e647

Please sign in to comment.