Unified · Split
| @@ -0,0 +1,28 @@ | |||
| 1 | import type { NextFetchEvent, NextRequest } from "next/server"; | ||
| 2 | import { NextResponse } from "next/server"; | ||
| 3 | import { authkitMiddleware } from "@workos-inc/authkit-nextjs"; | ||
| 4 | import { resolveWorkosRedirectUri } from "./lib/workos-redirect"; | ||
| 5 | |||
| 6 | function isConfigured(value: string | undefined): boolean { | ||
| 7 | const candidate = value?.trim(); | ||
| 8 | return Boolean(candidate && candidate.length > 0); | ||
| 9 | } | ||
| 10 | |||
| 11 | export function proxy(request: NextRequest, event: NextFetchEvent) { | ||
| 12 | if (!isConfigured(process.env.WORKOS_CLIENT_ID)) { | ||
| 13 | return NextResponse.next(); | ||
| 14 | } | ||
| 15 | |||
| 16 | const redirectUri = resolveWorkosRedirectUri(request); | ||
| 17 | if (!redirectUri) { | ||
| 18 | return NextResponse.next(); | ||
| 19 | } | ||
| 20 | |||
| 21 | return authkitMiddleware({ redirectUri })(request, event); | ||
| 22 | } | ||
| 23 | |||
| 24 | export default proxy; | ||
| 25 | |||
| 26 | export const config = { | ||
| 27 | matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"], | ||
| 28 | }; | ||