Skip to content

Commit

Permalink
fix: Allow withArcjet to pass next.js compiler checks (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaine-arcjet authored Dec 13, 2023
1 parent 30d0f63 commit f71c12b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions arcjet-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,13 @@ export function createMiddleware<const Rules extends (Primitive | Product)[]>(
* the request is blocked, a `NextApiResponse` instance will be returned based
* on the configured decision response.
*/
export function withArcjet(
export function withArcjet<Args extends [ArcjetNextRequest, ...unknown[]], Res>(
// TODO(#221): This type needs to be tightened to only allow Primitives or Products that don't have extra props
arcjet: ArcjetNext<(Primitive<EmptyObject> | Product<EmptyObject>)[]>,
handler: (...args: any[]) => any,
handler: (...args: Args) => Promise<Res>,
) {
return async (request: ArcjetNextRequest, ...rest: unknown[]) => {
return async (...args: Args) => {
const request = args[0];
const decision = await arcjet.protect(request);
if (decision.isDenied()) {
// TODO(#222): Content type negotiation using `Accept` header
Expand All @@ -272,7 +273,7 @@ export function withArcjet(
);
}
} else {
return handler(request, ...rest);
return handler(...args);
}
};
}

0 comments on commit f71c12b

Please sign in to comment.