Merge branch 'main' of http://39.117.244.52:3000/kjs/ERP-node into feature/unified-components-renewal

This commit is contained in:
kjs
2025-12-31 15:11:25 +09:00
108 changed files with 10743 additions and 4015 deletions

View File

@@ -331,6 +331,61 @@ export const useAuth = () => {
[apiCall, refreshUserData],
);
/**
* 회사 전환 처리 (WACE 관리자 전용)
*/
const switchCompany = useCallback(
async (companyCode: string): Promise<{ success: boolean; message: string }> => {
try {
// console.log("🔵 useAuth.switchCompany 시작:", companyCode);
setLoading(true);
setError(null);
// console.log("🔵 API 호출: POST /auth/switch-company");
const response = await apiCall<any>("POST", "/auth/switch-company", {
companyCode,
});
// console.log("🔵 API 응답:", response);
if (response.success && response.data?.token) {
// console.log("🔵 새 토큰 받음:", response.data.token.substring(0, 20) + "...");
// 새로운 JWT 토큰 저장
TokenManager.setToken(response.data.token);
// console.log("🔵 토큰 저장 완료");
// refreshUserData 호출하지 않고 바로 성공 반환
// (페이지 새로고침 시 자동으로 갱신됨)
// console.log("🔵 회사 전환 완료 (페이지 새로고침 필요)");
return {
success: true,
message: response.message || "회사 전환에 성공했습니다.",
};
} else {
// console.error("🔵 API 응답 실패:", response);
return {
success: false,
message: response.message || "회사 전환에 실패했습니다.",
};
}
} catch (error: any) {
// console.error("🔵 switchCompany 에러:", error);
const errorMessage = error.message || "회사 전환 중 오류가 발생했습니다.";
setError(errorMessage);
return {
success: false,
message: errorMessage,
};
} finally {
setLoading(false);
// console.log("🔵 switchCompany 완료");
}
},
[apiCall]
);
/**
* 로그아웃 처리
*/
@@ -493,6 +548,7 @@ export const useAuth = () => {
// 함수
login,
logout,
switchCompany, // 🆕 회사 전환 함수
checkMenuAuth,
refreshUserData,