From b3771d99e5dd631b15a45642270a03edafbb101d Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 23 Oct 2024 16:13:22 -0400 Subject: [PATCH 1/3] fix(nextjs): Include protect types in `auth` --- .changeset/selfish-pianos-push.md | 5 +++++ packages/nextjs/src/app-router/server/auth.ts | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/selfish-pianos-push.md diff --git a/.changeset/selfish-pianos-push.md b/.changeset/selfish-pianos-push.md new file mode 100644 index 00000000000..2a7d93fb13e --- /dev/null +++ b/.changeset/selfish-pianos-push.md @@ -0,0 +1,5 @@ +--- +"@clerk/nextjs": patch +--- + +Bug fix: Include protect types in `auth` diff --git a/packages/nextjs/src/app-router/server/auth.ts b/packages/nextjs/src/app-router/server/auth.ts index d00466897f2..dcb97f26f85 100644 --- a/packages/nextjs/src/app-router/server/auth.ts +++ b/packages/nextjs/src/app-router/server/auth.ts @@ -5,13 +5,20 @@ import { notFound, redirect } from 'next/navigation'; import { PUBLISHABLE_KEY, SIGN_IN_URL, SIGN_UP_URL } from '../../server/constants'; import { createGetAuth } from '../../server/createGetAuth'; import { authAuthHeaderMissing } from '../../server/errors'; +import type { AuthProtect } from '../../server/protect'; import { createProtect } from '../../server/protect'; import { decryptClerkRequestData, getAuthKeyFromRequest, getHeader } from '../../server/utils'; import { buildRequestLike } from './utils'; type Auth = AuthObject & { redirectToSignIn: RedirectFun> }; -export async function auth(): Promise { +export interface AuthFn { + (): Promise; + + protect: AuthProtect; +} + +export const auth: AuthFn = async () => { require('server-only'); const request = await buildRequestLike(); @@ -44,9 +51,9 @@ export async function auth(): Promise { }; return Object.assign(authObject, { redirectToSignIn }); -} +}; -auth.protect = async (...args: any[]) => { +auth.protect = async (...args) => { require('server-only'); const request = await buildRequestLike(); @@ -59,5 +66,7 @@ auth.protect = async (...args: any[]) => { notFound, redirect, }); + + // @ts-ignore return protect(...args); }; From 0ee464051f3c4ebd5975d08051531c7e03d0e821 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 23 Oct 2024 16:19:13 -0400 Subject: [PATCH 2/3] format --- packages/nextjs/src/app-router/server/auth.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nextjs/src/app-router/server/auth.ts b/packages/nextjs/src/app-router/server/auth.ts index dcb97f26f85..27e7f4c6fd5 100644 --- a/packages/nextjs/src/app-router/server/auth.ts +++ b/packages/nextjs/src/app-router/server/auth.ts @@ -14,7 +14,6 @@ type Auth = AuthObject & { redirectToSignIn: RedirectFun; - protect: AuthProtect; } From cd413e8f1d13a6fadedb4646f23e56476103dade Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 23 Oct 2024 16:33:56 -0400 Subject: [PATCH 3/3] add reason --- packages/nextjs/src/app-router/server/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/app-router/server/auth.ts b/packages/nextjs/src/app-router/server/auth.ts index 27e7f4c6fd5..e8e912cf435 100644 --- a/packages/nextjs/src/app-router/server/auth.ts +++ b/packages/nextjs/src/app-router/server/auth.ts @@ -66,6 +66,6 @@ auth.protect = async (...args) => { redirect, }); - // @ts-ignore + // @ts-expect-error TS flattens all possible combinations of the for AuthProtect signatures in a union. return protect(...args); };