[미들웨어 및 권한 시스템 개선] 기존 auth 미들웨어를 auth.global.ts로 통합하여 로그인 및 권한 체크 로직을 개선하고, 페이지 권한 확인 방식을 동적 라우팅 패턴으로 확장함. 불필요한 코드 제거 및 로그아웃 처리 로직 간소화.

This commit is contained in:
2025-09-25 11:28:12 +09:00
parent cb22e3904a
commit 51019d7f5f
6 changed files with 59 additions and 52 deletions

View File

@@ -72,7 +72,23 @@ export const usePermissionsStore = defineStore(
};
const hasPagePermission = (page: string): boolean => {
return getPagePaths().includes(page);
const pagePaths = getPagePaths();
// 1. 정확한 경로 매치 먼저 확인
if (pagePaths.includes(page)) {
return true;
}
// 2. 동적 라우팅 패턴 체크
for (const allowedPath of pagePaths) {
// 동적 라우팅 패턴: /[tabId]/path 형태
const dynamicPattern = new RegExp(`^/\\d+${allowedPath}$`);
if (dynamicPattern.test(page)) {
return true;
}
}
return false;
};
const hasPageGroupPermission = (pageGroup: string): boolean => {

View File

@@ -15,7 +15,6 @@ export const useTabsStore = defineStore("tabs", {
activeTab: 1,
}),
actions: {
// 서브메뉴 클릭 시 새 탭 생성 (중복 체크 추가)
async updateActiveTab(sub: {
label: string;
to: string;

View File

@@ -48,27 +48,19 @@ export const useUserStore = defineStore(
};
const logout = async () => {
try {
const response = await useApi("/members/logout", {
method: "post",
loadingMessage: "로그아웃 처리중...",
handleError: false,
showAlert: false,
});
await useApi("/members/logout", {
method: "post",
loadingMessage: "로그아웃 처리중...",
showAlert: false,
});
console.log("response:", response);
} catch (error) {
console.error(error);
} finally {
user.value = null;
isLoggedIn.value = false;
user.value = null;
isLoggedIn.value = false;
tabsStore.resetTabs();
permissionsStore.clearPermissions();
tabsStore.resetTabs();
permissionsStore.clearPermissions();
// 로그인 페이지로 이동
await navigateTo("/login");
}
await navigateTo("/login");
};
return {