(request: NextRequest)
| 21 | } |
| 22 | |
| 23 | export async function proxy(request: NextRequest) { |
| 24 | const { pathname } = request.nextUrl; |
| 25 | if (isPublicPath(pathname)) { |
| 26 | return NextResponse.next(); |
| 27 | } |
| 28 | |
| 29 | const config = getWebAuthConfig(); |
| 30 | const sessionCookie = request.cookies.get(config.cookieName)?.value; |
| 31 | const authenticated = await isAuthenticatedCookie(sessionCookie); |
| 32 | |
| 33 | if (authenticated) { |
| 34 | return NextResponse.next(); |
| 35 | } |
| 36 | |
| 37 | if (isApiPath(pathname)) { |
| 38 | return NextResponse.json( |
| 39 | { |
| 40 | error: config.enabled ? 'Unauthorized' : 'Web auth is not configured', |
| 41 | }, |
| 42 | { status: 401 }, |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | if (!config.enabled) { |
| 47 | return redirectTo(request, '/login', 307, '?error=config'); |
| 48 | } |
| 49 | return redirectTo(request, '/login'); |
| 50 | } |
| 51 | |
| 52 | export const config = { |
| 53 | matcher: ['/((?!_next/static|_next/image).*)'], |
nothing calls this directly
no test coverage detected