forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithAuth.ts
More file actions
20 lines (16 loc) · 862 Bytes
/
Copy pathwithAuth.ts
File metadata and controls
20 lines (16 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { Request, Response } from 'express';
import { clerkClient } from './clerkClient';
import { createClerkExpressWithAuth } from './clerkExpressWithAuth';
import type { ClerkMiddlewareOptions, WithAuthProp } from './types';
import { runMiddleware } from './utils';
type ApiHandlerWithAuth<TRequest, TResponse> = (req: WithAuthProp<TRequest>, res: TResponse) => void | Promise<void>;
// TODO: drop the Request/Response default values in v5 version
export function withAuth<TRequest extends Request = Request, TResponse extends Response = Response>(
handler: ApiHandlerWithAuth<TRequest, TResponse>,
options?: ClerkMiddlewareOptions,
): any {
return async (req: TRequest, res: TResponse) => {
await runMiddleware(req, res, createClerkExpressWithAuth({ clerkClient })(options));
return handler(req as WithAuthProp<TRequest>, res);
};
}