diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..4e087c9 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,21 @@ +import { NextResponse, NextRequest } from "next/server"; + +const protectedApi = [ + /^\/api\/posts\/[^/]+\/pin$/, + /^\/api\/posts\/[^/]+\/approve$/, +]; + +export function middleware(req: NextRequest) { + const { pathname } = req.nextUrl; + const needAuth = protectedApi.some((re) => re.test(pathname)); + if (!needAuth) return NextResponse.next(); + const uid = req.cookies.get("uid")?.value; + if (!uid) return new NextResponse(JSON.stringify({ error: "Unauthorized" }), { status: 401 }); + return NextResponse.next(); +} + +export const config = { + matcher: ["/api/:path*"], +}; + + diff --git a/todolist.txt b/todolist.txt index f3a98bd..c1d1a28 100644 --- a/todolist.txt +++ b/todolist.txt @@ -17,7 +17,7 @@ 3.2 비밀번호 해시/검증 로직(bcrypt) 적용 o 3.3 세션/쿠키(HttpOnly/SameSite/Secure) 및 토큰 저장 전략 o 3.4 비밀번호 재설정 토큰 발급/검증/만료 o -3.5 보호 라우팅 미들웨어 및 인증 가드 +3.5 보호 라우팅 미들웨어 및 인증 가드 o 3.6 로그인 시도 레이트리밋(정책은 보안/정책 참조) [상태관리/데이터] @@ -94,4 +94,8 @@ 13.2 CI 파이프라인 구성(테스트/빌드/린트) 13.3 배포 설정 및 헬스체크 엔드포인트 13.4 모니터링/알림(Sentry 등) 연동 -13.5 백업/복구 전략 수립 \ No newline at end of file +13.5 백업/복구 전략 수립 + + +14 +배포용 상태 적용 \ No newline at end of file