31 lines
		
	
	
		
			1008 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1008 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
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 =>
 | 
						|
      to.path.startsWith(route)
 | 
						|
    );
 | 
						|
 | 
						|
    // 로그인 체크
 | 
						|
    if (isProtectedRoute && !userStore.isLoggedIn) {
 | 
						|
      // 인증되지 않은 사용자를 로그인 페이지로 리다이렉트
 | 
						|
      return navigateTo("/login");
 | 
						|
    }
 | 
						|
 | 
						|
    // API 권한 체크 (로그인된 사용자만)
 | 
						|
    if (userStore.isLoggedIn) {
 | 
						|
      const currentPath = to.path;
 | 
						|
      if (!permissionsStore.hasApiPermission(currentPath)) {
 | 
						|
        // 권한이 없는 경우 홈으로 리다이렉트
 | 
						|
        return navigateTo("/");
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
});
 |