File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/**
22 * Configuration for dashboard routes that require authentication.
3- *
3+ *
44 * To add a new protected route, simply add the path to this array.
55 * To remove protection from a route, remove it from this array.
6- *
6+ *
77 * Routes are matched using prefix matching, so nested routes under
88 * a protected path will also be protected (e.g., /dashboard/projects/123
99 * is protected if /dashboard/projects is in this array).
1010 */
1111export const PROTECTED_DASHBOARD_ROUTES = [
12- ' /dashboard/projects' ,
13- ' /dashboard/sheet' ,
12+ " /dashboard/projects" ,
13+ " /dashboard/sheet" ,
1414] as const ;
15-
Original file line number Diff line number Diff line change @@ -11,18 +11,18 @@ export async function middleware(req: NextRequest) {
1111 req : adaptedReq as any ,
1212 secret : process . env . NEXTAUTH_SECRET ,
1313 } ) ;
14-
14+
1515 const pathname = req . nextUrl . pathname ;
16-
16+
1717 const isProtectedRoute = PROTECTED_DASHBOARD_ROUTES . some ( ( path ) =>
1818 pathname . startsWith ( path )
1919 ) ;
20-
20+
2121 if ( isProtectedRoute && ! token ) {
2222 const signInUrl = new URL ( "/login" , req . url ) ;
2323 signInUrl . searchParams . set ( "callbackUrl" , pathname ) ;
2424 return NextResponse . redirect ( signInUrl ) ;
2525 }
26-
26+
2727 return NextResponse . next ( ) ;
2828}
You can’t perform that action at this time.
0 commit comments