Files
frontend/apps/wr/app/store/common/auth/index.tsx
T
2025-10-01 20:51:15 +09:00

88 lines
2.2 KiB
TypeScript

import { fetchType, getFetchWithCount } from "@/components/lib/api";
import { getUserInfo } from "@common/components/api";
import toast from "react-hot-toast";
export type authState = {
auth: {
mngAuthrtYn: string;
inqAuthrtYn: string;
regAuthrtYn: string;
mdfcnAuthrtYn: string;
delAuthrtYn: string;
laeSeCd: string;
};
};
export type authType = authState & authActions;
export const authStateExport: authState = {
auth: {
mngAuthrtYn: "Y",
inqAuthrtYn: "Y",
regAuthrtYn: "Y",
mdfcnAuthrtYn: "Y",
delAuthrtYn: "Y",
laeSeCd: "",
},
};
export type authActions = {
getMenuAuthrts: (menuCd: number) => void;
getLaeSeCdCheck: () => Promise<void>;
};
export const authActionsExport: (set: any, get: any) => authActions = (
set: any,
get: any
) => {
return {
getMenuAuthrts: async (menuCd: number) => {
try {
const response = await getFetchWithCount(
fetchType.CS,
`/cms-service/api/v1/menu-authrts/pageinfo/${menuCd}`
);
set((state: authState) => {
return {
...state,
auth: {
...state.auth,
mngAuthrtYn: response[0].mngAuthrtYn,
inqAuthrtYn: response[0].mngAuthrtYn,
regAuthrtYn: response[0].mngAuthrtYn,
mdfcnAuthrtYn: response[0].mngAuthrtYn,
delAuthrtYn: response[0].mngAuthrtYn,
},
};
});
} catch (e) {
toast.error(
"권한 정보를 가져오는 중 오류가 발생했습니다. 관리자에게 문의하세요."
);
console.error("Error fetching menu authorities:", e);
}
},
getLaeSeCdCheck: async () => {
try {
const current = get().auth.laeSeCd;
if (current && current !== "") {
return;
}
const infoMe = await getUserInfo();
const isLaeSeCd =
infoMe.laeSeCd.slice(0, 2) === "G3" ? infoMe.laeSeCd.slice(2) : "0";
set((state: authState) => ({
...state,
auth: {
...state.auth,
laeSeCd: isLaeSeCd,
},
}));
} catch (e) {
console.error("laeSeCd check error", e);
}
},
};
};