diff --git a/src/hooks/useTokenRefresher.tsx b/src/hooks/useTokenRefresher.tsx index ebfe3122..84c03f3b 100644 --- a/src/hooks/useTokenRefresher.tsx +++ b/src/hooks/useTokenRefresher.tsx @@ -8,18 +8,16 @@ export default function TokenRefresher() { const navigate = useNavigate(); const { openAlert } = useModal(); - const user = localStorage.getItem("user"); - if (user) { - if (!JSON.parse(user)?.role || !JSON.parse(user)?.refreshToken) { + useEffect(() => { + const user = localStorage.getItem("user"); + if (!user || !JSON.parse(user)?.role || !JSON.parse(user)?.refreshToken) { // 기존에 존재하던 유저 role, refreshToken 유무로 임시로 토큰 제거 후 리로드 localStorage.clear(); openAlert({ title: "다시 로그인 해주세요." }); // window.location.reload(); - return <>; + return; } - } - useEffect(() => { const interceptor = instance.interceptors.response.use( (response) => response, async (error) => {