From 6c9d0690aa9462001c389a30607f017e5e8f4961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B5=ED=9D=AC=20=EA=B9=80?= Date: Wed, 22 Jan 2025 04:11:46 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AF=B8=EB=93=A4=EC=9B=A8=EC=96=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/middleware.js 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*'], +};