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..e8e912cf435 100644 --- a/packages/nextjs/src/app-router/server/auth.ts +++ b/packages/nextjs/src/app-router/server/auth.ts @@ -5,13 +5,19 @@ 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 +50,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 +65,7 @@ auth.protect = async (...args: any[]) => { notFound, redirect, }); + + // @ts-expect-error TS flattens all possible combinations of the for AuthProtect signatures in a union. return protect(...args); };