Skip to content

Commit

Permalink
Fix session expiry detection (#6472)
Browse files Browse the repository at this point in the history
* fix session expiry detection

* Fix logout bug
  • Loading branch information
Ashesh3 authored Oct 20, 2023
1 parent 08193ba commit 33f103d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/Redux/fireRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/Routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit 33f103d

Please sign in to comment.