Skip to content

Commit c7f7a84

Browse files
committed
fix(auth): rely on requireAdmin for admin routes
1 parent bfd7e6c commit c7f7a84

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

middleware.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ const { auth } = NextAuth(authConfig);
1111
export default auth((req) => {
1212
const { nextUrl } = req;
1313
const isLoggedIn = !!req.auth;
14-
const role = req.auth?.user?.role;
1514
const approved = req.auth?.user?.approved;
1615

1716
const path = nextUrl.pathname;
1817

1918
// 카톡/슬랙 등 외부 미리보기 크롤러용 OG/twitter 이미지 — 의도적으로 public.
2019
// 메타데이터(날짜/장소/사진) 노출은 동아리 내부 서비스 + URL 추측이 아주 어렵지 않은
21-
// 점을 알면서도, 카톡 공유 UX 가치를 더 크게 봐서 수용. (회고-Week3 참조.)
20+
// 점을 알면서도, 카톡 공유 UX 가치를 더 크게 봐서 수용.
2221
if (path.endsWith("/opengraph-image") || path.endsWith("/twitter-image")) {
2322
return;
2423
}
@@ -39,10 +38,11 @@ export default auth((req) => {
3938
return NextResponse.redirect(url);
4039
}
4140

42-
// /admin/* 는 ADMIN 만. 그 외는 404 처럼 처리.
43-
if (path.startsWith("/admin") && role !== "ADMIN") {
44-
return NextResponse.rewrite(new URL("/404-not-found", nextUrl));
45-
}
41+
// 주의:
42+
// /admin/* 의 권한 판정은 middleware 에서 하지 않는다.
43+
// Edge-safe authConfig 는 DB fresh fetch 를 못 해서 role/approved 가 stale 하거나
44+
// 아예 없는 상태가 될 수 있다. 실제 권한은 page/action 진입점의 requireAdmin()
45+
// 이 DB 기준으로 최종 판정한다.
4646

4747
return;
4848
});

0 commit comments

Comments
 (0)