diff --git a/src/utils/request.ts b/src/utils/request.ts index 8798014..1ac21d4 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -75,6 +75,14 @@ request.interceptors.response.use(async (response, options) => { await freshTokenUsingPost(param).then((res) => { if (res.retcode) { localStorage.setItem('token', res.data?.accessToken); + } else { + localStorage.clear(); + history.replace({ + pathname: '/user/login', + search: stringify({ + redirect: window.location.href, + }), + }); } }); const url = response.url.replace(`${process.env.BASE_URL}`, ''); @@ -122,6 +130,14 @@ request.interceptors.response.use(async (response, options) => { await freshTokenUsingPost(param).then((res) => { if (res.retcode) { localStorage.setItem('token', res.data?.accessToken); + } else { + localStorage.clear(); + history.replace({ + pathname: '/user/login', + search: stringify({ + redirect: window.location.href, + }), + }); } }); const url = response.url.replace(`${process.env.BASE_URL}`, '');