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);
window.$dialog?.error({ // prevent repeated pop-ups
title: 'Error', if (!request.state.isLogout) {
content: response.data.msg, request.state.isLogout = true;
positiveText: $t('common.confirm'), window.$dialog?.error({
maskClosable: false, title: 'Error',
onPositiveClick() { content: response.data.msg,
logoutAndCleanup(); positiveText: $t('common.confirm'),
}, maskClosable: false,
onClose() { onPositiveClick() {
logoutAndCleanup(); request.state.isLogout = false;
} logoutAndCleanup();
}); },
onClose() {
request.state.isLogout = false;
logoutAndCleanup();
}
});
}
return null; return null;
} }