| 20 | } |
| 21 | |
| 22 | function isRouteMatch(pathname: string, routes: string[]): boolean { |
| 23 | return routes.some((route) => { |
| 24 | if (route === pathname) { |
| 25 | return true |
| 26 | } |
| 27 | |
| 28 | if (route.endsWith("**")) { |
| 29 | const prefix = route.slice(0, -2) |
| 30 | |
| 31 | return pathname.startsWith(prefix) |
| 32 | } |
| 33 | |
| 34 | if (route.endsWith("*")) { |
| 35 | const prefix = route.slice(0, -1) |
| 36 | |
| 37 | return pathname.startsWith(prefix) && !pathname.slice(prefix.length).includes("/") |
| 38 | } |
| 39 | |
| 40 | return false |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | function handleUnauthenticated(request: NextRequest, pathname: string): NextResponse { |
| 45 | if (pathname.startsWith("/api/")) { |