diff options
author | Sunil Shetye | 2025-04-07 00:44:27 +0530 |
---|---|---|
committer | Sunil Shetye | 2025-04-07 15:38:16 +0530 |
commit | cc9a94df7dbd1a82cb86f83c88c5a443488f4cfe (patch) | |
tree | d4ffd5101c664e6f50a84c7b9a069b7610e30a0e | |
parent | 7492d9cd8d9e28f2df244a92a2d0d7d56f1d660b (diff) | |
download | Common-Interface-Project-cc9a94df7dbd1a82cb86f83c88c5a443488f4cfe.tar.gz Common-Interface-Project-cc9a94df7dbd1a82cb86f83c88c5a443488f4cfe.tar.bz2 Common-Interface-Project-cc9a94df7dbd1a82cb86f83c88c5a443488f4cfe.zip |
ensure that only one request is made at one time
-rw-r--r-- | blocks/eda-frontend/src/utils/Api.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/blocks/eda-frontend/src/utils/Api.js b/blocks/eda-frontend/src/utils/Api.js index 7fe47f67..f9302174 100644 --- a/blocks/eda-frontend/src/utils/Api.js +++ b/blocks/eda-frontend/src/utils/Api.js @@ -59,6 +59,8 @@ const refreshSession = async () => { } } +let refreshingSession = null + api.interceptors.request.use(async (config) => { // Avoid infinite loop by skipping the interceptor for session refresh requests if (config.url.includes('simulation/get_session')) { @@ -69,11 +71,17 @@ api.interceptors.request.use(async (config) => { // Check if session is expired and refresh if necessary if (!sessionId || isSessionExpired()) { - console.log('Session expired, refreshing...') - deleteCookie('sessionid') + if (!refreshingSession) { + console.log('Session expired, refreshing...') + deleteCookie('sessionid') + + refreshingSession = refreshSession().finally(() => { + refreshingSession = null + }) + } // Refresh session but avoid triggering interceptor again - sessionId = await refreshSession() + sessionId = await refreshingSession if (!sessionId) { return Promise.reject(new Error('Failed to refresh session')) } |