[메뉴 권한 1차 작업]
This commit is contained in:
@@ -2,26 +2,29 @@ export default defineNuxtRouteMiddleware((to, _from) => {
|
||||
// 클라이언트 사이드에서만 실행
|
||||
if (import.meta.client) {
|
||||
const userStore = useUserStore();
|
||||
const permissionsStore = usePermissionsStore();
|
||||
|
||||
// 보호된 라우트 목록(메뉴 확정되면 수정)
|
||||
const protectedRoutes = ["/admin", "/profile", "/dashboard"];
|
||||
|
||||
// 현재 라우트가 보호된 라우트인지 확인
|
||||
const isProtectedRoute = protectedRoutes.some((route) =>
|
||||
const isProtectedRoute = protectedRoutes.some(route =>
|
||||
to.path.startsWith(route)
|
||||
);
|
||||
|
||||
// 관리자 전용 라우트 확인
|
||||
const isAdminRoute = to.path.startsWith("/admin");
|
||||
|
||||
// 로그인 체크
|
||||
if (isProtectedRoute && !userStore.isLoggedIn) {
|
||||
// 인증되지 않은 사용자를 로그인 페이지로 리다이렉트
|
||||
return navigateTo("/login");
|
||||
}
|
||||
|
||||
if (isAdminRoute && !userStore.isAdmin) {
|
||||
// 관리자가 아닌 사용자를 홈 페이지로 리다이렉트
|
||||
return navigateTo("/");
|
||||
// API 권한 체크 (로그인된 사용자만)
|
||||
if (userStore.isLoggedIn) {
|
||||
const currentPath = to.path;
|
||||
if (!permissionsStore.hasApiPermission(currentPath)) {
|
||||
// 권한이 없는 경우 홈으로 리다이렉트
|
||||
return navigateTo("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user