diff --git a/src/middleware.js b/src/middleware.js new file mode 100644 index 0000000..cf112c0 --- /dev/null +++ b/src/middleware.js @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; + +export function middleware(req) { + // 현재 요청 URL + const pathname = decodeURIComponent(req.nextUrl.pathname); + + // 로그인 상태 확인 (예제: 쿠키에서 토큰 확인) + const token = req.cookies.get('token'); + + // 특정 경로에서는 미들웨어를 적용하지 않음 + if (!token && pathname !== '/auth/login') { + // 리디렉션 경로 지정 + return NextResponse.redirect(new URL('/auth/login', req.url)); + } + + return NextResponse.next(); +} + +// 모든 페이지에서 미들웨어 적용 (한글 경로 포함) +export const config = { + matcher: ['/product/:path*', '/dashboard/:path*', '/profile/:path*', '/settings/:path*'], +};