Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-pianos-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nextjs": patch
---

Bug fix: Include protect types in `auth`
14 changes: 11 additions & 3 deletions packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof redirect>> };

export async function auth(): Promise<Auth> {
export interface AuthFn {
(): Promise<Auth>;
protect: AuthProtect;
}

export const auth: AuthFn = async () => {
require('server-only');

const request = await buildRequestLike();
Expand Down Expand Up @@ -44,9 +50,9 @@ export async function auth(): Promise<Auth> {
};

return Object.assign(authObject, { redirectToSignIn });
}
};

auth.protect = async (...args: any[]) => {
auth.protect = async (...args) => {
require('server-only');

const request = await buildRequestLike();
Expand All @@ -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);
};
Loading