|
|
@ -4,6 +4,13 @@ import { useSelector, useDispatch } from '@src/redux/store'; |
|
|
|
import { checkToken } from '@src/redux/features/account/auth/authThunk'; |
|
|
|
import { checkToken } from '@src/redux/features/account/auth/authThunk'; |
|
|
|
import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState'; |
|
|
|
import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState'; |
|
|
|
import { clientDispatchTopMenu } from '@src/redux/features/layout/layoutSlice'; |
|
|
|
import { clientDispatchTopMenu } from '@src/redux/features/layout/layoutSlice'; |
|
|
|
|
|
|
|
import { openModal } from '@src/redux/features/comn/message/messageSlice'; |
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
COOKIE_ACCESS_TOKEN, |
|
|
|
|
|
|
|
COOKIE_REFRESH_TOKEN, |
|
|
|
|
|
|
|
cookieStorage |
|
|
|
|
|
|
|
} from '@src/utility/authService/cookie'; |
|
|
|
|
|
|
|
import { ERROR_TITLE, ERROR_MESSAGE } from '@src/configs/msgConst'; |
|
|
|
|
|
|
|
|
|
|
|
interface IOption { |
|
|
|
interface IOption { |
|
|
|
authRoute?: boolean; |
|
|
|
authRoute?: boolean; |
|
|
@ -24,12 +31,16 @@ export default function (SpecificComponent: ReactNode, option: IOption) { |
|
|
|
) => JSX.Element; |
|
|
|
) => JSX.Element; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
dispatch(checkToken() as any).then(({ payload: { result } }) => { |
|
|
|
if (props.match.path === '/account/login') { |
|
|
|
|
|
|
|
setIsRender(true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dispatch(checkToken() as any).then(({ payload }) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션
|
|
|
|
// 로그인 해야만 접근 가능한 페이지인지 체크하는 옵션
|
|
|
|
const { authRoute } = option; |
|
|
|
const { authRoute } = option; |
|
|
|
|
|
|
|
|
|
|
|
if (!result) { |
|
|
|
if (!payload?.result) { |
|
|
|
if (authRoute) { |
|
|
|
if (authRoute) { |
|
|
|
props.history.replace('/account/login'); |
|
|
|
props.history.replace('/account/login'); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -42,9 +53,7 @@ export default function (SpecificComponent: ReactNode, option: IOption) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
setIsRender(true); |
|
|
|
setIsRender(true); |
|
|
|
} catch (error) { |
|
|
|
} catch (error) {} |
|
|
|
// props.history.replace('/account/login');
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
return () => { |
|
|
|
return () => { |
|
|
|
setIsRender(false); |
|
|
|
setIsRender(false); |
|
|
|