From 5c30cabe958d899a5fb3f48f4f20848d7a62d5d2 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:33:31 +0530 Subject: [PATCH 1/2] fix session expiry detection --- src/Redux/fireRequest.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Redux/fireRequest.tsx b/src/Redux/fireRequest.tsx index bf083e23a92..06a7da14865 100644 --- a/src/Redux/fireRequest.tsx +++ b/src/Redux/fireRequest.tsx @@ -93,11 +93,15 @@ export const fireRequest = ( const config: any = { headers: {}, }; - if (!request.noAuth && localStorage.getItem(LocalStorageKeys.accessToken)) { - config.headers["Authorization"] = - "Bearer " + localStorage.getItem(LocalStorageKeys.accessToken); - } else { - // TODO: get access token + if (!request.noAuth) { + const access_token = localStorage.getItem(LocalStorageKeys.accessToken); + if (access_token) { + config.headers["Authorization"] = "Bearer " + access_token; + } else { + // We do not have access token, so we need to redirect to session expired page + window.location.href = "/session-expired"; + return; + } } const axiosApiCall: any = axios.create(config); From ae4db1b90a2897354cb03012dcb12caddf624534 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:26:07 +0530 Subject: [PATCH 2/2] Fix logout bug --- src/Redux/fireRequest.tsx | 4 ++-- src/Routers/AppRouter.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Redux/fireRequest.tsx b/src/Redux/fireRequest.tsx index 06a7da14865..3d8c677d47d 100644 --- a/src/Redux/fireRequest.tsx +++ b/src/Redux/fireRequest.tsx @@ -98,8 +98,8 @@ export const fireRequest = ( if (access_token) { config.headers["Authorization"] = "Bearer " + access_token; } else { - // We do not have access token, so we need to redirect to session expired page - window.location.href = "/session-expired"; + // The access token is missing from the local storage. Redirect to login page. + window.location.href = "/"; return; } } diff --git a/src/Routers/AppRouter.tsx b/src/Routers/AppRouter.tsx index 0f6108b00e3..d098a480149 100644 --- a/src/Routers/AppRouter.tsx +++ b/src/Routers/AppRouter.tsx @@ -65,7 +65,12 @@ export default function AppRouter() { useEffect(() => { addEventListener("storage", (event: any) => { - if (event.key === LocalStorageKeys.accessToken && !event.newValue) { + if ( + [LocalStorageKeys.accessToken, LocalStorageKeys.refreshToken].includes( + event.key + ) && + !event.newValue + ) { handleSignOut(true); } });