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