(handler: AdminRouteHandler)
| 14 | * Returns early with an error response if authentication fails. |
| 15 | */ |
| 16 | export function withAdminAuth(handler: AdminRouteHandler): AdminRouteHandler { |
| 17 | return async (request: NextRequest) => { |
| 18 | const auth = authenticateAdminRequest(request) |
| 19 | |
| 20 | if (!auth.authenticated) { |
| 21 | if (auth.notConfigured) { |
| 22 | return notConfiguredResponse() |
| 23 | } |
| 24 | return unauthorizedResponse(auth.error) |
| 25 | } |
| 26 | |
| 27 | return handler(request) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Wrap a route handler with params with admin authentication. |
no test coverage detected