From 95fdb5c3d4959b2bb5e27973bb8cfbd014f7dd87 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Thu, 9 Oct 2025 21:35:07 +0530 Subject: [PATCH] Remove Onyx.connect() for the key: ONYXKEYS.STASHED_SESSION in src/libs/actions/Delegate.ts --- src/Expensify.tsx | 3 ++- src/components/AccountSwitcher.tsx | 3 ++- src/libs/actions/Delegate.ts | 20 +++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 086737c7d113..4b7edd471cce 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -110,6 +110,7 @@ function Expensify() { const [onboardingInitialPath] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true}); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); const [stashedCredentials] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); + const [stashedSession] = useOnyx(ONYXKEYS.STASHED_SESSION, {canBeMissing: true}); useDebugShortcut(); usePriorityMode(); @@ -281,7 +282,7 @@ function Expensify() { if (account?.delegatedAccess?.delegates?.some((d) => d.email === account?.delegatedAccess?.delegate)) { return; } - disconnect({stashedCredentials}); + disconnect({stashedCredentials, stashedSession}); }, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate]); // Display a blank page until the onyx migration completes diff --git a/src/components/AccountSwitcher.tsx b/src/components/AccountSwitcher.tsx index 4260f8c8b92d..0004ca7eec13 100644 --- a/src/components/AccountSwitcher.tsx +++ b/src/components/AccountSwitcher.tsx @@ -50,6 +50,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); const [stashedCredentials] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true}); + const [stashedSession] = useOnyx(ONYXKEYS.STASHED_SESSION, {canBeMissing: true}); const buttonRef = useRef(null); const {windowHeight} = useWindowDimensions(); @@ -142,7 +143,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { close(() => setShouldShowOfflineModal(true)); return; } - disconnect({stashedCredentials}); + disconnect({stashedCredentials, stashedSession}); }, }), currentUserMenuItem, diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 1548d738b856..b2ce8873fd3e 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -20,12 +20,6 @@ import {getCurrentUserAccountID} from './Report'; import updateSessionAuthTokens from './Session/updateSessionAuthTokens'; import updateSessionUser from './Session/updateSessionUser'; -let stashedSession: Session = {}; -Onyx.connect({ - key: ONYXKEYS.STASHED_SESSION, - callback: (value) => (stashedSession = value ?? {}), -}); - let activePolicyID: OnyxEntry; Onyx.connect({ key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, @@ -91,7 +85,11 @@ type WithSession = { session: Session | undefined; }; -type DisconnectParams = WithStashedCredentials; +type WithStashedSession = { + stashedSession: Session | undefined; +}; + +type DisconnectParams = WithStashedCredentials & WithStashedSession; // Clear delegator-level errors type ClearDelegatorErrorsParams = WithDelegatedAccess; @@ -121,7 +119,7 @@ type ClearDelegateRolePendingActionParams = WithEmail & WithDelegatedAccess; * Connects the user as a delegate to another account. * Returns a Promise that resolves to true on success, false on failure, or undefined if not applicable. */ -function connect({email, delegatedAccess, credentials, session,isFromOldDot = false}: ConnectParams) { +function connect({email, delegatedAccess, credentials, session, isFromOldDot = false}: ConnectParams) { if (!delegatedAccess?.delegators && !isFromOldDot) { return; } @@ -225,7 +223,7 @@ function connect({email, delegatedAccess, credentials, session,isFromOldDot = fa }); } -function disconnect({stashedCredentials}: DisconnectParams) { +function disconnect({stashedCredentials, stashedSession}: DisconnectParams) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -268,13 +266,13 @@ function disconnect({stashedCredentials}: DisconnectParams) { .then((response) => { if (!response?.authToken || !response?.encryptedAuthToken) { Log.alert('[Delegate] No auth token returned while disconnecting as a delegate'); - restoreDelegateSession(stashedSession); + restoreDelegateSession(stashedSession ?? {}); return; } if (!response?.requesterID || !response?.requesterEmail) { Log.alert('[Delegate] No requester data returned while disconnecting as a delegate'); - restoreDelegateSession(stashedSession); + restoreDelegateSession(stashedSession ?? {}); return; }