diff --git a/src/Redux/fireRequest.tsx b/src/Redux/fireRequest.tsx index bf083e23a92..3d8c677d47d 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 { + // The access token is missing from the local storage. Redirect to login page. + window.location.href = "/"; + return; + } } const axiosApiCall: any = axios.create(config); 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); } });