fix: prevent expired-token login refresh loop

This commit is contained in:
whyour
2026-09-19 13:23:28 +08:00
parent d9833c17d5
commit 6acb665369
3 changed files with 158 additions and 9 deletions
+3 -7
View File
@@ -114,13 +114,9 @@ export default function () {
history.push('/error');
}
})
.catch((error) => {
const responseStatus = error.response.status;
if (responseStatus !== 401) {
history.push('/error');
} else {
window.location.reload();
}
.catch(() => {
// Health is anonymous; a failure must not trigger a page reload loop.
history.push('/error');
})
.finally(() => setInitLoading(false));
};
+3 -2
View File
@@ -49,9 +49,9 @@ const errorHandler = function (
if ([502, 504].includes(responseStatus)) {
history.push('/error');
} else if (responseStatus === 401) {
localStorage.removeItem(config.authKey);
if (history.location.pathname !== '/login') {
message.error(intl.get('登录已过期,请重新登录'));
localStorage.removeItem(config.authKey);
history.push('/login');
}
} else {
@@ -84,6 +84,7 @@ let _request = axios.create({
});
const apiWhiteList = [
`${config.baseUrl}api/health`,
`${config.baseUrl}api/user/login`,
`${config.baseUrl}open/auth/token`,
`${config.baseUrl}api/user/two-factor/login`,
@@ -106,8 +107,8 @@ _request.interceptors.response.use(async (response) => {
if ([502, 504].includes(responseStatus)) {
history.push('/error');
} else if (responseStatus === 401) {
localStorage.removeItem(config.authKey);
if (history.location.pathname !== '/login') {
localStorage.removeItem(config.authKey);
history.push('/login');
}
} else {