From b13dbc303324de14941ff5792ac0c6ae3d179561 Mon Sep 17 00:00:00 2001 From: Jared Schoeny Date: Wed, 22 Jul 2026 14:21:53 -0600 Subject: [PATCH] Better optimize middleware matcher --- src/middleware.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/middleware.ts b/src/middleware.ts index e3c0192..102e5c8 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -6,6 +6,8 @@ export async function middleware(request: NextRequest) { return await updateSession(request) } +// All values must be hardcoded in the middleware config, +// which is why the project ID is hardcoded for the cookie key. export const config = { matcher: [ /* @@ -15,6 +17,19 @@ export const config = { * - favicon.ico (favicon file) * Feel free to modify this pattern to include more paths. */ - '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', + { + // Production + source: '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', + has: [ + { type: 'cookie', key: 'sb-scfxbqapigdjfebqwmoj-auth-token' }, + ] + }, + { + // Local development + source: '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', + has: [ + { type: 'cookie', key: 'sb-127-auth-token' }, + ] + }, ], }