Browse Source

token 검증 로직 수정(token 없을시 검증 api 요청 제외)

master
김장현 3 weeks ago
parent
commit
70b863cab5
  1. 72
      src/router/hoc/authenticationCheck.tsx

72
src/router/hoc/authenticationCheck.tsx

@ -25,59 +25,43 @@ export default function (SpecificComponent: ReactNode, option: IOption) {
props: IProps props: IProps
) => JSX.Element; ) => JSX.Element;
// useEffect(() => {
// if (user?.cptAuthCode === 'DF0002') {
// const pathname = history.location.pathname;
// if (
// !(
// pathname == '/operation/approvals' ||
// pathname == '/rightMenu' ||
// pathname == 'control/approvals' ||
// pathname == 'control/rightMenu'
// )
// ) {
// // id 나누면 주석 풀 것!!!
// // props.history.replace('/operation/approvals');
// return;
// }
// }
// }, [user]);
useEffect(() => { useEffect(() => {
// if (props.match.path === '/account/login') { // if (props.match.path === '/account/login') {
// setIsRender(true); // setIsRender(true);
// return; // return;
// } // }
dispatch(checkToken() as any).then(({ payload }) => { if (getDecodeToken()) {
try { dispatch(checkToken() as any).then(({ payload }) => {
// 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션 try {
const { authRoute } = option; // 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션
const { authRoute } = option;
if (!payload?.result) { if (!payload?.result) {
if (authRoute) { if (authRoute) {
props.history.replace('/account/login'); props.history.replace('/account/login');
return; return;
} }
} else { } else {
if (!authRoute) { if (!authRoute) {
const decodeToken = getDecodeToken(); const decodeToken = getDecodeToken();
if (decodeToken) { if (decodeToken) {
if (decodeToken.cptAuthCode === 'DF0002') { if (decodeToken.cptAuthCode === 'DF0002') {
props.history.replace('/control/approvals'); props.history.replace('/control/approvals');
} else if (decodeToken.cptAuthCode === 'DF0002-1') { } else if (decodeToken.cptAuthCode === 'DF0002-1') {
props.history.replace('/operation/approvals'); props.history.replace('/operation/approvals');
} else { } else {
localStorage.setItem('topMenuCd', '/'); localStorage.setItem('topMenuCd', '/');
dispatch(clientDispatchTopMenu('/')); dispatch(clientDispatchTopMenu('/'));
props.history.replace('/control'); props.history.replace('/control');
}
} }
} }
} }
} } catch (error) {}
setIsRender(true); });
} catch (error) {} }
}); setIsRender(true);
return () => { return () => {
setIsRender(false); setIsRender(false);
}; };

Loading…
Cancel
Save