invoke auth0 middleware only when relevant

This commit is contained in:
Ramnique Singh 2025-06-25 10:53:30 +05:30
parent 44f8088d9b
commit 59a631e6df

View file

@ -8,11 +8,9 @@ const corsOptions = {
export async function middleware(request: NextRequest, event: NextFetchEvent) {
const authRes = await auth0.middleware(request);
// Check if the request path starts with /api/auth/
if (request.nextUrl.pathname.startsWith('/auth')) {
return authRes;
return await auth0.middleware(request);
}
// Check if the request path starts with /api/
@ -44,7 +42,7 @@ export async function middleware(request: NextRequest, event: NextFetchEvent) {
request.nextUrl.pathname.startsWith('/onboarding')) {
// Skip auth check if USE_AUTH is not enabled
if (process.env.USE_AUTH === 'true') {
return authRes;
return await auth0.middleware(request);
}
}