미들웨어 추가
This commit is contained in:
parent
3f04849bb9
commit
6c9d0690aa
22
src/middleware.js
Normal file
22
src/middleware.js
Normal file
@ -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*'],
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user