fix(projects): 修复登录过期不弹窗问题

This commit is contained in:
AN
2025-07-17 16:00:50 +08:00
parent 2587f8cbfa
commit e485f680c7

View File

@ -77,14 +77,15 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
// when the backend response code is in `modalLogoutCodes`, it means the user will be logged out by displaying a modal
const modalLogoutCodes = import.meta.env.VITE_SERVICE_MODAL_LOGOUT_CODES?.split(',') || [];
if (modalLogoutCodes.includes(responseCode) && isLogin) {
const isExist = request.state.errMsgStack.includes(response.data.msg);
const isExist = request.state.errMsgStack && request.state.errMsgStack.includes(response.data.msg);
if (isExist) {
return null;
}
if (!window.location.pathname?.startsWith('/login')) {
if (window.location.pathname?.startsWith('/login')) {
logoutAndCleanup();
return null;
}
request.state.errMsgStack = [...(request.state.errMsgStack || []), response.data.msg];
// prevent the user from refreshing the page
window.addEventListener('beforeunload', handleLogout);
@ -106,9 +107,6 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
request.cancelAllRequest();
return null;
}
logoutAndCleanup();
return null;
}
// when the backend response code is in `expiredTokenCodes`, it means the token is expired, and refresh token
// the api `refreshToken` can not return error code in `expiredTokenCodes`, otherwise it will be a dead loop, should return `logoutCodes` or `modalLogoutCodes`