MCPcopy Create free account
hub / github.com/auth0-samples/auth0-nextjs-samples / proxy

Function proxy

Sample-01/proxy.js:4–26  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

2import { auth0 } from "./lib/auth0"
3
4export 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
28export const config = {
29 matcher: [

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected