28 lines
		
	
	
		
			900 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			900 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
export default defineNuxtRouteMiddleware((to, _from) => {
 | 
						|
  // 클라이언트 사이드에서만 실행
 | 
						|
  if (import.meta.client) {
 | 
						|
    const userStore = useUserStore();
 | 
						|
 | 
						|
    // 보호된 라우트 목록(메뉴 확정되면 수정)
 | 
						|
    const protectedRoutes = ["/admin", "/profile", "/dashboard"];
 | 
						|
 | 
						|
    // 현재 라우트가 보호된 라우트인지 확인
 | 
						|
    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("/");
 | 
						|
    }
 | 
						|
  }
 | 
						|
});
 |