diff --git a/frontend/src/authentication/components/AuthGuard.js b/frontend/src/authentication/components/AuthGuard.js index 642169610..4c2843e37 100644 --- a/frontend/src/authentication/components/AuthGuard.js +++ b/frontend/src/authentication/components/AuthGuard.js @@ -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 !== '/' @@ -31,6 +33,8 @@ export const AuthGuard = (props) => { return ; } + // 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') diff --git a/frontend/src/authentication/contexts/GenericAuthContext.js b/frontend/src/authentication/contexts/GenericAuthContext.js index f01d0865b..07fbcc4df 100644 --- a/frontend/src/authentication/contexts/GenericAuthContext.js +++ b/frontend/src/authentication/contexts/GenericAuthContext.js @@ -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); } @@ -282,10 +280,7 @@ export const GenericAuthProvider = (props) => { } }); } - - if (sessionStorage.getItem('window-location')) { - sessionStorage.removeItem('window-location'); - } + sessionStorage.removeItem('window-location'); }; return (