mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-01 05:13:50 +08:00
fix: prevent expired-token login refresh loop
This commit is contained in:
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user