feat(projects): Prevent repeated pop-ups after login expiration

This commit is contained in:
xlsea 2024-03-27 19:14:59 +08:00
parent 1a7070f02b
commit 6eb0ab4235

View File

@ -10,6 +10,8 @@ const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === '
const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy); const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);
interface InstanceState { interface InstanceState {
/** whether the request is logout */
isLogout: boolean;
/** whether the request is refreshing token */ /** whether the request is refreshing token */
isRefreshingToken: boolean; isRefreshingToken: boolean;
} }
@ -62,18 +64,24 @@ export const request = createFlatRequest<App.Service.Response, InstanceState>(
// prevent the user from refreshing the page // prevent the user from refreshing the page
window.addEventListener('beforeunload', handleLogout); window.addEventListener('beforeunload', handleLogout);
// prevent repeated pop-ups
if (!request.state.isLogout) {
request.state.isLogout = true;
window.$dialog?.error({ window.$dialog?.error({
title: 'Error', title: 'Error',
content: response.data.msg, content: response.data.msg,
positiveText: $t('common.confirm'), positiveText: $t('common.confirm'),
maskClosable: false, maskClosable: false,
onPositiveClick() { onPositiveClick() {
request.state.isLogout = false;
logoutAndCleanup(); logoutAndCleanup();
}, },
onClose() { onClose() {
request.state.isLogout = false;
logoutAndCleanup(); logoutAndCleanup();
} }
}); });
}
return null; return null;
} }