File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { NextResponse } from "next/server" ;
22import type { NextRequest } from "next/server" ;
33
4- const loginNeedPages = [ "/mentor" , "/my" , "/community/" ] ; // 로그인 필요페이지
4+ const loginNeedPages = [ "/mentor" , "/my" ] ; // 로그인 필요페이지
55
66export function middleware ( request : NextRequest ) {
77 const url = request . nextUrl . clone ( ) ;
@@ -21,10 +21,14 @@ export function middleware(request: NextRequest) {
2121 // HTTP-only 쿠키의 refreshToken 확인
2222 const refreshToken = request . cookies . get ( "refreshToken" ) ?. value ;
2323
24- // 정확한 경로 매칭 - startsWith 대신 정확한 경로나 세그먼트 기반 매칭 사용
25- const needLogin = loginNeedPages . some ( ( path ) => {
26- return url . pathname === path || url . pathname . match ( new RegExp ( `^${ path } (/|$)` ) ) ;
27- } ) ;
24+ // /community는 통과, /community/ 하위 경로는 로그인 필요
25+ const isCommunitySubRoute = url . pathname . startsWith ( "/community/" ) ;
26+
27+ // 정확한 경로 매칭
28+ const needLogin =
29+ loginNeedPages . some ( ( path ) => {
30+ return url . pathname === path || url . pathname . startsWith ( path + "/" ) ;
31+ } ) || isCommunitySubRoute ; // /community/ 하위 경로도 로그인 필요
2832
2933 if ( needLogin && ! refreshToken ) {
3034 url . pathname = "/login" ;
You can’t perform that action at this time.
0 commit comments