File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,29 +8,34 @@ export const config = {
88 ] ,
99} ;
1010
11- const publicRoutes = [
12- AUTH_LINKS . signup ,
13- AUTH_LINKS . login ,
14- ROUTES . SURVEY . TAKE ,
15- ROUTES . LANDING ,
16- ] ;
11+ const publicRoutes = [ AUTH_LINKS . signup , AUTH_LINKS . login , ROUTES . LANDING ] ;
12+
1713const publicRoutePatterns = [ / ^ \/ s u r v e y \/ t a k e \/ [ ^ / ] + $ / ] ;
1814
1915export function middleware ( request : NextRequest ) {
2016 const isLogin = request . cookies . get ( 'isLogin' ) ;
2117 const currentPath = request . nextUrl . pathname ;
2218
23- const isPublicRoute =
24- publicRoutes . includes ( currentPath ) ||
25- publicRoutePatterns . some ( ( pattern ) => pattern . test ( currentPath ) ) ;
19+ const isPublicRoute = publicRoutes . includes ( currentPath ) ;
2620
27- if ( ! isLogin && ! isPublicRoute ) {
21+ if (
22+ ! isLogin &&
23+ ! isPublicRoute &&
24+ ! publicRoutePatterns . some ( ( pattern ) => pattern . test ( currentPath ) )
25+ ) {
2826 const url = request . nextUrl . clone ( ) ;
2927 url . pathname = AUTH_LINKS . login ;
3028 return NextResponse . redirect ( url ) ;
3129 }
3230
33- if ( isLogin && publicRoutes . includes ( currentPath ) ) {
31+ if (
32+ ! isLogin &&
33+ publicRoutePatterns . some ( ( pattern ) => pattern . test ( currentPath ) )
34+ ) {
35+ return NextResponse . next ( ) ;
36+ }
37+
38+ if ( isLogin && isPublicRoute ) {
3439 const url = request . nextUrl . clone ( ) ;
3540 url . pathname = NAV_LINKS [ 0 ] . href ;
3641 return NextResponse . redirect ( url ) ;
You can’t perform that action at this time.
0 commit comments