File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,17 @@ import { cookies } from "next/headers";
2
2
import { NextRequest , NextResponse } from "next/server" ;
3
3
import { CookieNames } from "@/app/actions/session" ;
4
4
5
- const protectedRoutes = [ "/ questions/*" , "/ user/*" ] ;
6
- const publicRoutes = [ "/" , "/ auth/login/" , "/ auth/register" ] ;
5
+ const protectedRoutes = [ / ^ \/ q u e s t i o n s \/ / , / ^ \/ u s e r \/ / ] ;
6
+ const publicRoutes = [ / ^ \/ $ / , / ^ \/ a u t h \ /l o g i n \/ $ / , / ^ \/ a u t h \ /r e g i s t e r \/ $ / ] ;
7
7
8
8
const isValidSession = ( ) => {
9
9
return cookies ( ) . has ( "session" ) ;
10
10
} ;
11
11
12
12
export async function middleware ( request : NextRequest ) {
13
13
const path = request . nextUrl . pathname ;
14
- const isProtectedRoute = protectedRoutes . includes ( path ) ;
15
- const isPublicRoute = publicRoutes . includes ( path ) ;
14
+ const isProtectedRoute = protectedRoutes . some ( ( route ) => route . test ( path ) ) ;
15
+ const isPublicRoute = publicRoutes . some ( ( route ) => route . test ( path ) ) ;
16
16
17
17
if ( isPublicRoute ) {
18
18
return NextResponse . next ( ) ;
You can’t perform that action at this time.
0 commit comments