(request)
| 2 | import { auth0 } from "./lib/auth0" |
| 3 | |
| 4 | export async function proxy(request) { |
| 5 | const authRes = await auth0.middleware(request); |
| 6 | |
| 7 | // authentication routes — let the middleware handle it |
| 8 | if (request.nextUrl.pathname.startsWith("/auth")) { |
| 9 | return authRes; |
| 10 | } |
| 11 | |
| 12 | // public routes — no need to check for session |
| 13 | if (request.nextUrl.pathname === ("/")) { |
| 14 | return authRes; |
| 15 | } |
| 16 | |
| 17 | const { origin } = new URL(request.url) |
| 18 | const session = await auth0.getSession() |
| 19 | |
| 20 | // user does not have a session — redirect to login |
| 21 | if (!session) { |
| 22 | return NextResponse.redirect(`${origin}/auth/login`) |
| 23 | } |
| 24 | |
| 25 | return authRes |
| 26 | } |
| 27 | |
| 28 | export const config = { |
| 29 | matcher: [ |
nothing calls this directly
no outgoing calls
no test coverage detected