From 1ee26db273c181646561de0c2ad528f5d299211a Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:44:25 +0800 Subject: [PATCH 1/3] move clean up to Session cleanupSession --- src/libs/actions/Session/index.ts | 33 +++++++++++++++++++++++++++++ src/libs/actions/SignInRedirect.ts | 34 ------------------------------ 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 82b51651cacc..82d371e16bed 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -4,14 +4,20 @@ import {ChannelAuthorizationCallback} from 'pusher-js/with-encryption'; import {Linking} from 'react-native'; import Onyx, {OnyxUpdate} from 'react-native-onyx'; import {ValueOf} from 'type-fest'; +import * as PersistedRequests from '@libs/actions/PersistedRequests'; import * as API from '@libs/API'; import * as Authentication from '@libs/Authentication'; import * as ErrorUtils from '@libs/ErrorUtils'; +import HttpUtils from '@libs/HttpUtils'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; +import navigationRef from '@libs/Navigation/navigationRef'; +import * as MainQueue from '@libs/Network/MainQueue'; import * as NetworkStore from '@libs/Network/NetworkStore'; +import NetworkConnection from '@libs/NetworkConnection'; import * as Pusher from '@libs/Pusher/pusher'; import * as ReportUtils from '@libs/ReportUtils'; +import * as SessionUtils from '@libs/SessionUtils'; import Timers from '@libs/Timers'; import {hideContextMenu} from '@pages/home/report/ContextMenu/ReportActionContextMenu'; import * as Device from '@userActions/Device'; @@ -23,6 +29,7 @@ import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import SCREENS from '@src/SCREENS'; import Credentials from '@src/types/onyx/Credentials'; import {AutoAuthState} from '@src/types/onyx/Session'; import clearCache from './clearCache'; @@ -583,14 +590,40 @@ function clearSignInData() { }); } +/** + * Reset all current params of the Home route + */ +function resetHomeRouteParams() { + Navigation.isNavigationReady().then(() => { + const routes = navigationRef.current?.getState().routes; + const homeRoute = routes?.find((route) => route.name === SCREENS.HOME); + + const emptyParams: Record = {}; + Object.keys(homeRoute?.params ?? {}).forEach((paramKey) => { + emptyParams[paramKey] = undefined; + }); + + Navigation.setParams(emptyParams, homeRoute?.key ?? ''); + Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false); + }); +} + /** * Put any logic that needs to run when we are signed out here. This can be triggered when the current tab or another tab signs out. + * - Cancels pending network calls - any lingering requests are discarded to prevent unwanted storage writes + * - Clears all current params of the Home route - the login page URL should not contain any parameter */ function cleanupSession() { Pusher.disconnect(); Timers.clearAll(); Welcome.resetReadyCheck(); PriorityMode.resetHasReadRequiredDataFromStorage(); + MainQueue.clear(); + HttpUtils.cancelPendingRequests(); + PersistedRequests.clear(); + NetworkConnection.clearReconnectionCallbacks(); + SessionUtils.resetDidUserLogInDuringSession(); + resetHomeRouteParams(); } function clearAccountMessages() { diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index 9ca4e6813567..6c9e7f55d887 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -1,14 +1,6 @@ import Onyx from 'react-native-onyx'; import * as ErrorUtils from '@libs/ErrorUtils'; -import HttpUtils from '@libs/HttpUtils'; -import Navigation from '@libs/Navigation/Navigation'; -import navigationRef from '@libs/Navigation/navigationRef'; -import * as MainQueue from '@libs/Network/MainQueue'; -import NetworkConnection from '@libs/NetworkConnection'; -import * as SessionUtils from '@libs/SessionUtils'; import ONYXKEYS, {OnyxKey} from '@src/ONYXKEYS'; -import SCREENS from '@src/SCREENS'; -import * as PersistedRequests from './PersistedRequests'; let currentIsOffline: boolean | undefined; let currentShouldForceOffline: boolean | undefined; @@ -45,42 +37,16 @@ function clearStorageAndRedirect(errorMessage?: string) { }); } -/** - * Reset all current params of the Home route - */ -function resetHomeRouteParams() { - Navigation.isNavigationReady().then(() => { - const routes = navigationRef.current?.getState().routes; - const homeRoute = routes?.find((route) => route.name === SCREENS.HOME); - - const emptyParams: Record = {}; - Object.keys(homeRoute?.params ?? {}).forEach((paramKey) => { - emptyParams[paramKey] = undefined; - }); - - Navigation.setParams(emptyParams, homeRoute?.key ?? ''); - Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false); - }); -} - /** * Cleanup actions resulting in the user being redirected to the Sign-in page * - Clears the Onyx store - removing the authToken redirects the user to the Sign-in page - * - Cancels pending network calls - any lingering requests are discarded to prevent unwanted storage writes - * - Clears all current params of the Home route - the login page URL should not contain any parameter * * Normally this method would live in Session.js, but that would cause a circular dependency with Network.js. * * @param [errorMessage] error message to be displayed on the sign in page */ function redirectToSignIn(errorMessage?: string) { - MainQueue.clear(); - HttpUtils.cancelPendingRequests(); - PersistedRequests.clear(); - NetworkConnection.clearReconnectionCallbacks(); clearStorageAndRedirect(errorMessage); - resetHomeRouteParams(); - SessionUtils.resetDidUserLogInDuringSession(); } export default redirectToSignIn; From 25cce87e0b7ab5bb271ecfd33e534cc6fb1852ae Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:44:47 +0800 Subject: [PATCH 2/3] remove immediate clean sign out after close account --- src/libs/actions/User.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 3aa0e9642cdb..9fd2d19f4520 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -69,8 +69,6 @@ function closeAccount(message) { ], }, ); - // Run cleanup actions to prevent reconnection callbacks from blocking logging in again - redirectToSignIn(); } /** From 86497f36314e215789c8dd999df32326b6ac056d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 13 Dec 2023 00:55:01 +0800 Subject: [PATCH 3/3] fix lint --- src/libs/actions/User.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 9fd2d19f4520..544164d6e36d 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -17,7 +17,6 @@ import * as OnyxUpdates from './OnyxUpdates'; import * as PersonalDetails from './PersonalDetails'; import * as Report from './Report'; import * as Session from './Session'; -import redirectToSignIn from './SignInRedirect'; let currentUserAccountID = ''; let currentEmail = '';