2025-08-08 13:11:33 +09:00
|
|
|
export default defineNuxtRouteMiddleware((to, _from) => {
|
|
|
|
|
// 클라이언트 사이드에서만 실행
|
|
|
|
|
if (import.meta.client) {
|
|
|
|
|
const userStore = useUserStore();
|
2025-09-23 14:15:32 +09:00
|
|
|
const permissionsStore = usePermissionsStore();
|
2025-08-08 13:11:33 +09:00
|
|
|
|
|
|
|
|
// 보호된 라우트 목록(메뉴 확정되면 수정)
|
|
|
|
|
const protectedRoutes = ["/admin", "/profile", "/dashboard"];
|
|
|
|
|
|
|
|
|
|
// 현재 라우트가 보호된 라우트인지 확인
|
2025-09-23 14:15:32 +09:00
|
|
|
const isProtectedRoute = protectedRoutes.some(route =>
|
2025-08-08 13:11:33 +09:00
|
|
|
to.path.startsWith(route)
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-23 14:15:32 +09:00
|
|
|
// 로그인 체크
|
2025-08-08 13:11:33 +09:00
|
|
|
if (isProtectedRoute && !userStore.isLoggedIn) {
|
|
|
|
|
// 인증되지 않은 사용자를 로그인 페이지로 리다이렉트
|
|
|
|
|
return navigateTo("/login");
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 14:15:32 +09:00
|
|
|
// API 권한 체크 (로그인된 사용자만)
|
|
|
|
|
if (userStore.isLoggedIn) {
|
|
|
|
|
const currentPath = to.path;
|
|
|
|
|
if (!permissionsStore.hasApiPermission(currentPath)) {
|
|
|
|
|
// 권한이 없는 경우 홈으로 리다이렉트
|
|
|
|
|
return navigateTo("/");
|
|
|
|
|
}
|
2025-08-08 13:11:33 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|