이전 코드

const silentRefresh = async (originRequest: InternalAxiosRequestConfig) => {
  try {
    const newToken = await updateToken();
    storage.set(newToken);
    setAxiosAuthHeader(originRequest, newToken);
    return await publicApi(originRequest);
  } catch {
    removeToken();

    if (isClient()) {
      history.pushState('', '', '/');
    }
  }
};

문제 상황

스크린샷 2024-04-23 오후 3.23.51.png

원인

스크린샷 2024-04-23 오후 3.27.55.png

해결

const silentRefresh = async (originRequest: InternalAxiosRequestConfig) => {
  try {
    const newToken = await updateToken();
    storage.set(newToken);
    setAxiosAuthHeader(originRequest, newToken);
    return await publicApi(originRequest);
  } catch (error) {
    removeToken();

    if (isClient()) {
      window.location.reload();
    }

    return Promise.reject(error);
  }
};