Skip to content

Commit

Permalink
Adding Comments and removing sessionStorage.getItmem check in Generic…
Browse files Browse the repository at this point in the history
…AuthContext.js
  • Loading branch information
TejasRGitHub authored and trajopadhye committed Mar 25, 2024
1 parent 8de0066 commit cdfe85b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 4 additions & 0 deletions frontend/src/authentication/components/AuthGuard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const AuthGuard = (props) => {
setRequestedLocation(location.pathname);
}

// If the user is not authenticated and if the session storage is empty for the key 'window-location'
// Also, another check of location.path is added to prevent overriding the window-location object when the user logs out and redirected to the landing page URL. Here, when the user is logged out the session storage stores '/' which is not needed
if (
!sessionStorage.getItem('window-location') &&
location.pathname !== '/'
Expand All @@ -31,6 +33,8 @@ export const AuthGuard = (props) => {
return <Navigate to={requestedLocation} />;
}

// When session storage contained path is not same as the current location.pathname ( usually after authentication )
// Redirect the user to the session storage stored pathname.
if (
sessionStorage.getItem('window-location') &&
location.pathname !== sessionStorage.getItem('window-location')
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/authentication/contexts/GenericAuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ export const GenericAuthProvider = (props) => {
}
});
}
if (sessionStorage.getItem('window-location')) {
sessionStorage.removeItem('window-location');
}
sessionStorage.removeItem('window-location');
} catch (error) {
console.error('Failed to signout', error);
}
Expand Down Expand Up @@ -282,10 +280,7 @@ export const GenericAuthProvider = (props) => {
}
});
}

if (sessionStorage.getItem('window-location')) {
sessionStorage.removeItem('window-location');
}
sessionStorage.removeItem('window-location');
};

return (
Expand Down

0 comments on commit cdfe85b

Please sign in to comment.