Skip to content

fix: 60931 session storage clear on logout #61762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function getSettingsTabStateFromSessionStorage(): PartialState<NavigationState>
return undefined;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function clearSessionStorage() {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getLastVisitedSettingsPath(state: NavigationState | PartialState<NavigationState>): Route | undefined {
return undefined;
Expand All @@ -17,4 +20,4 @@ function getLastVisitedWorkspaceScreen() {
return undefined;
}

export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsTabPathToSessionStorage, getSettingsTabStateFromSessionStorage};
export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsTabPathToSessionStorage, getSettingsTabStateFromSessionStorage, clearSessionStorage};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function saveSettingsTabPathToSessionStorage(url: string) {
sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_TAB_PATH, url);
}

function clearSessionStorage() {
sessionStorage.clear();
}

function getSettingsTabStateFromSessionStorage(): PartialState<NavigationState> | undefined {
const lastVisitedSettingsPath = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_VISITED_SETTINGS_TAB_PATH);
if (!lastVisitedSettingsPath) {
Expand All @@ -34,4 +38,4 @@ function getLastVisitedWorkspaceScreen() {
return workspaceScreenName ?? undefined;
}

export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsTabPathToSessionStorage, getSettingsTabStateFromSessionStorage};
export {getLastVisitedWorkspaceScreen, getLastVisitedSettingsPath, saveSettingsTabPathToSessionStorage, getSettingsTabStateFromSessionStorage, clearSessionStorage};
5 changes: 4 additions & 1 deletion src/libs/actions/SignInRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import {getMicroSecondOnyxErrorWithMessage} from '@libs/ErrorUtils';
import {clearSessionStorage} from '@libs/Navigation/helpers/getLastVisitedWorkspace';
import type {OnyxKey} from '@src/ONYXKEYS';
import ONYXKEYS from '@src/ONYXKEYS';
import {clearAllPolicies} from './Policy/Policy';
Expand Down Expand Up @@ -50,7 +51,9 @@ function clearStorageAndRedirect(errorMessage?: string): Promise<void> {
* @param [errorMessage] error message to be displayed on the sign in page
*/
function redirectToSignIn(errorMessage?: string): Promise<void> {
return clearStorageAndRedirect(errorMessage);
return clearStorageAndRedirect(errorMessage).then(() => {
clearSessionStorage();
});
Comment on lines +54 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit different from your original proposal. What's the reason for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since sessionStorage isn't available on mobile, a clearSessionStorage() function was created that does nothing in native environments to prevent errors.
Calling clearSessionStorage() before clearStorageAndRedirect() caused inconsistent behavior (session sometimes resetting and sometimes working fine), so the session is now cleared only after logout is successfully completed to ensure stability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Make senses

}

export default redirectToSignIn;
Loading