2025-09-25 11:28:12 +09:00
|
|
|
export default defineNuxtRouteMiddleware(async (to, _from) => {
|
2025-10-21 15:54:01 +09:00
|
|
|
const userStore = useUserStore();
|
|
|
|
|
const { hasPagePermission } = usePermission();
|
2025-09-25 11:28:12 +09:00
|
|
|
|
2025-10-21 15:54:01 +09:00
|
|
|
// 공개 라우트 목록 (로그인 없이 접근 가능)
|
|
|
|
|
const publicRoutes = ["/login", "/register", "/auth-error"];
|
2025-09-25 11:28:12 +09:00
|
|
|
|
2025-10-21 15:54:01 +09:00
|
|
|
// 공개 라우트인지 확인
|
|
|
|
|
const isPublicRoute = publicRoutes.some(route => to.path === route);
|
2025-09-25 11:28:12 +09:00
|
|
|
|
2025-10-21 15:54:01 +09:00
|
|
|
// 공개 라우트가 아닌 경우 로그인 체크
|
|
|
|
|
if (!isPublicRoute && !userStore.isLoggedIn) {
|
|
|
|
|
return navigateTo("/login");
|
|
|
|
|
}
|
2025-09-25 11:28:12 +09:00
|
|
|
|
2025-10-21 15:54:01 +09:00
|
|
|
// 로그인된 사용자의 경우 권한 체크
|
|
|
|
|
if (userStore.isLoggedIn) {
|
|
|
|
|
// 홈화면 경로는 항상 허용
|
|
|
|
|
if (to.path === "/" || to.path === "/1/") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-09-25 11:28:12 +09:00
|
|
|
|
2025-10-21 15:54:01 +09:00
|
|
|
// 페이지 권한 체크
|
|
|
|
|
if (!hasPagePermission(to.path)) {
|
|
|
|
|
console.log(`페이지 권한이 없습니다.: ${to.path}`);
|
|
|
|
|
alert(`페이지 권한이 없습니다.`);
|
|
|
|
|
return navigateTo("/");
|
2025-09-25 11:28:12 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|