Skip to content

Commit df844f7

Browse files
authored
Merge pull request Expensify#69000 from allgandalf/fix/66494
Remove Onyx.connect() for the key: ONYXKEYS.CREDENTIALS in src/libs/actions/Delegate.ts
2 parents 876573d + 54a8ce0 commit df844f7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/components/AccountSwitcher.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
4747
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
4848
const [accountID] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false, selector: accountIDSelector});
4949
const [isDebugModeEnabled] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true});
50+
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true});
51+
5052
const buttonRef = useRef<HTMLDivElement>(null);
5153
const {windowHeight} = useWindowDimensions();
5254

@@ -158,7 +160,7 @@ function AccountSwitcher({isScreenFocused}: AccountSwitcherProps) {
158160
close(() => setShouldShowOfflineModal(true));
159161
return;
160162
}
161-
connect({email, delegatedAccess: account?.delegatedAccess});
163+
connect({email, delegatedAccess: account?.delegatedAccess, credentials});
162164
},
163165
});
164166
});

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function AuthScreens() {
178178
const {toggleSearch} = useSearchRouterContext();
179179
const currentUrl = getCurrentUrl();
180180
const delegatorEmail = getSearchParamFromUrl(currentUrl, 'delegatorEmail');
181-
181+
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS, {canBeMissing: true});
182182
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {
183183
canBeMissing: true,
184184
});
@@ -275,7 +275,7 @@ function AuthScreens() {
275275
// or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp() and connect() for delegator from OldDot.
276276
if (SessionUtils.didUserLogInDuringSession() || delegatorEmail) {
277277
if (delegatorEmail) {
278-
connect({email: delegatorEmail, delegatedAccess: account?.delegatedAccess, isFromOldDot: true})
278+
connect({email: delegatorEmail, delegatedAccess: account?.delegatedAccess, credentials, isFromOldDot: true})
279279
?.then((success) => {
280280
App.setAppLoading(!!success);
281281
})

src/libs/actions/Delegate.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ import {getCurrentUserAccountID} from './Report';
2020
import updateSessionAuthTokens from './Session/updateSessionAuthTokens';
2121
import updateSessionUser from './Session/updateSessionUser';
2222

23-
let credentials: Credentials = {};
24-
Onyx.connect({
25-
key: ONYXKEYS.CREDENTIALS,
26-
callback: (value) => (credentials = value ?? {}),
27-
});
28-
2923
let stashedCredentials: Credentials = {};
3024
Onyx.connect({
3125
key: ONYXKEYS.STASHED_CREDENTIALS,
@@ -76,6 +70,10 @@ type WithDelegatedAccess = {
7670
delegatedAccess: DelegatedAccess | undefined;
7771
};
7872

73+
type WithCredentials = {
74+
credentials: Credentials | undefined;
75+
};
76+
7977
type WithEmail = {
8078
email: string;
8179
};
@@ -116,7 +114,7 @@ type UpdateDelegateRoleParams = WithEmail & WithRole & WithValidateCode & WithDe
116114
type IsConnectedAsDelegateParams = WithDelegatedAccess;
117115

118116
// Connect as delegate
119-
type ConnectParams = WithEmail & WithDelegatedAccess & WithOldDotFlag;
117+
type ConnectParams = WithEmail & WithDelegatedAccess & WithOldDotFlag & WithCredentials;
120118

121119
// Clear pending action for role update
122120
type ClearDelegateRolePendingActionParams = WithEmail & WithDelegatedAccess;
@@ -125,12 +123,12 @@ type ClearDelegateRolePendingActionParams = WithEmail & WithDelegatedAccess;
125123
* Connects the user as a delegate to another account.
126124
* Returns a Promise that resolves to true on success, false on failure, or undefined if not applicable.
127125
*/
128-
function connect({email, delegatedAccess, isFromOldDot = false}: ConnectParams) {
126+
function connect({email, delegatedAccess, credentials, isFromOldDot = false}: ConnectParams) {
129127
if (!delegatedAccess?.delegators && !isFromOldDot) {
130128
return;
131129
}
132130

133-
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, credentials);
131+
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, credentials ?? {});
134132
Onyx.set(ONYXKEYS.STASHED_SESSION, session);
135133

136134
const previousAccountID = getCurrentUserAccountID();

0 commit comments

Comments
 (0)