diff --git a/package.json b/package.json index 243a8cd71a95..a7779e37c9dd 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=215 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=214 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 960876ff3edb..7f9c2cefac67 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -33,13 +33,19 @@ type PolicyParamsForOpenOrReconnect = { policyIDList: string[]; }; -let currentUserAccountID: number | undefined; -let currentUserEmail: string; -Onyx.connect({ +// `currentSessionData` is only used in actions, not during render. So `Onyx.connectWithoutView` is appropriate. +// If React components need this value in the future, use `useOnyx` instead. +let currentSessionData: {accountID?: number; email: string} = { + accountID: undefined, + email: '', +}; +Onyx.connectWithoutView({ key: ONYXKEYS.SESSION, callback: (val) => { - currentUserAccountID = val?.accountID; - currentUserEmail = val?.email ?? ''; + currentSessionData = { + accountID: val?.accountID, + email: val?.email ?? '', + }; }, }); @@ -170,7 +176,7 @@ function setLocale(locale: Locale, currentPreferredLocale: Locale | undefined) { } // If user is not signed in, change just locally. - if (!currentUserAccountID) { + if (!currentSessionData.accountID) { Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, locale); return; } @@ -563,7 +569,7 @@ function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true, isMa // If the route that is being handled is a magic link, email and shortLivedAuthToken should not be attached to the url // to prevent signing into the wrong account - if (!currentUserAccountID || !shouldAuthenticateWithCurrentAccount) { + if (!currentSessionData.accountID || !shouldAuthenticateWithCurrentAccount) { Browser.openRouteInDesktopApp(); return; } @@ -575,13 +581,13 @@ function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true, isMa if (!response) { Log.alert( 'Trying to redirect via deep link, but the response is empty. User likely not authenticated.', - {response, shouldAuthenticateWithCurrentAccount, currentUserAccountID}, + {response, shouldAuthenticateWithCurrentAccount, currentUserAccountID: currentSessionData.accountID}, true, ); return; } - Browser.openRouteInDesktopApp(response.shortLivedAuthToken, currentUserEmail, isMagicLink ? '/r' : initialRoute); + Browser.openRouteInDesktopApp(response.shortLivedAuthToken, currentSessionData.email, isMagicLink ? '/r' : initialRoute); }); }