From 570dd0b9eaa38ae343acb33e154b136b3cca20eb Mon Sep 17 00:00:00 2001 From: allgandalf Date: Thu, 9 Oct 2025 21:11:56 +0530 Subject: [PATCH 1/2] remove usage of ONYXKEYS.STASHED_CREDENTIALS --- src/Expensify.tsx | 3 ++- src/components/AccountSwitcher.tsx | 3 ++- src/libs/actions/Delegate.ts | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 048d686cf959..086737c7d113 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -109,6 +109,7 @@ function Expensify() { const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true}); 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}); useDebugShortcut(); usePriorityMode(); @@ -280,7 +281,7 @@ function Expensify() { if (account?.delegatedAccess?.delegates?.some((d) => d.email === account?.delegatedAccess?.delegate)) { return; } - disconnect(); + disconnect({stashedCredentials}); }, [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 cd31d56302a7..21c11b4e5c55 100644 --- a/src/components/AccountSwitcher.tsx +++ b/src/components/AccountSwitcher.tsx @@ -48,6 +48,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: accountIDSelector}); const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); + const [stashedCredentials] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); const buttonRef = useRef(null); const {windowHeight} = useWindowDimensions(); @@ -140,7 +141,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { close(() => setShouldShowOfflineModal(true)); return; } - disconnect(); + disconnect({stashedCredentials}); }, }), currentUserMenuItem, diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index ab8a847615c1..530f789429c8 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 stashedCredentials: Credentials = {}; -Onyx.connect({ - key: ONYXKEYS.STASHED_CREDENTIALS, - callback: (value) => (stashedCredentials = value ?? {}), -}); - let session: Session = {}; Onyx.connect({ key: ONYXKEYS.SESSION, @@ -95,6 +89,12 @@ type WithOldDotFlag = { isFromOldDot?: boolean; }; +type WithStashedCredentials = { + stashedCredentials: Credentials | undefined; +}; + +type DisconnectParams = WithStashedCredentials; + // Clear delegator-level errors type ClearDelegatorErrorsParams = WithDelegatedAccess; @@ -227,7 +227,7 @@ function connect({email, delegatedAccess, credentials, isFromOldDot = false}: Co }); } -function disconnect() { +function disconnect({stashedCredentials}: DisconnectParams) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, From 674491b182e6cc2ffc8698294b87da7933510a50 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Fri, 10 Oct 2025 09:28:53 +0530 Subject: [PATCH 2/2] Implement reviewers suggestions --- src/Expensify.tsx | 4 ++-- src/components/AccountSwitcher.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 086737c7d113..9ee57669ce18 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -109,7 +109,7 @@ function Expensify() { const [currentOnboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true}); 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 [stashedCredentials = CONST.EMPTY_OBJECT] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); useDebugShortcut(); usePriorityMode(); @@ -282,7 +282,7 @@ function Expensify() { return; } disconnect({stashedCredentials}); - }, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate]); + }, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate, stashedCredentials]); // Display a blank page until the onyx migration completes if (!isOnyxMigrated) { diff --git a/src/components/AccountSwitcher.tsx b/src/components/AccountSwitcher.tsx index 21c11b4e5c55..fc8ada5e5e9e 100644 --- a/src/components/AccountSwitcher.tsx +++ b/src/components/AccountSwitcher.tsx @@ -48,7 +48,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) { const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: accountIDSelector}); const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true}); const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true}); - const [stashedCredentials] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); + const [stashedCredentials = CONST.EMPTY_OBJECT] = useOnyx(ONYXKEYS.STASHED_CREDENTIALS, {canBeMissing: true}); const buttonRef = useRef(null); const {windowHeight} = useWindowDimensions();