( handler: AdminRouteHandlerWithParams<TParams> )
| 33 | * Returns early with an error response if authentication fails. |
| 34 | */ |
| 35 | export function withAdminAuthParams<TParams>( |
| 36 | handler: AdminRouteHandlerWithParams<TParams> |
| 37 | ): AdminRouteHandlerWithParams<TParams> { |
| 38 | return async (request: NextRequest, context: { params: Promise<TParams> }) => { |
| 39 | const auth = authenticateAdminRequest(request) |
| 40 | |
| 41 | if (!auth.authenticated) { |
| 42 | if (auth.notConfigured) { |
| 43 | return notConfiguredResponse() |
| 44 | } |
| 45 | return unauthorizedResponse(auth.error) |
| 46 | } |
| 47 | |
| 48 | return handler(request, context) |
| 49 | } |
| 50 | } |
no test coverage detected