Skip to content

Commit a6c717e

Browse files
committed
Seed LAST_FULL_RECONNECT_TIME before Onyx.clear on delegate transition
1 parent 72483d1 commit a6c717e

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/libs/actions/Delegate.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {OnyxEntry, OnyxKey, OnyxUpdate} from 'react-native-onyx';
44
import * as API from '@libs/API';
55
import type {AddDelegateParams as APIAddDelegateParams, RemoveDelegateParams as APIRemoveDelegateParams, UpdateDelegateRoleParams as APIUpdateDelegateRoleParams} from '@libs/API/parameters';
66
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
7+
import DateUtils from '@libs/DateUtils';
78
import * as ErrorUtils from '@libs/ErrorUtils';
89
import Log from '@libs/Log';
910
import {clearPreservedSearchNavigatorStates} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState';
@@ -41,6 +42,20 @@ const KEYS_TO_PRESERVE_DELEGATE_ACCESS = [
4142
ONYXKEYS.COLLECTION.DEVICE_BIOMETRICS,
4243
];
4344

45+
/**
46+
* Reset Onyx for a delegate-access transition while seeding LAST_FULL_RECONNECT_TIME=now.
47+
*
48+
* subscribeToFullReconnect compares this timestamp against the server-supplied
49+
* NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE that lands in OpenApp's response.onyxData.
50+
* Because applyHTTPSOnyxUpdates applies response.onyxData before successData, the
51+
* timestamp would still be empty when the comparison runs, falsely triggering a
52+
* duplicate ReconnectApp on top of the OpenApp that follows the transition. Seeding
53+
* it to `now` short-circuits the subscriber until OpenApp's successData refreshes it.
54+
*/
55+
function clearOnyxForDelegateTransition(): Promise<void> {
56+
return Onyx.merge(ONYXKEYS.LAST_FULL_RECONNECT_TIME, DateUtils.getDBTime()).then(() => Onyx.clear([...KEYS_TO_PRESERVE_DELEGATE_ACCESS, ONYXKEYS.LAST_FULL_RECONNECT_TIME]));
57+
}
58+
4459
type WithDelegatedAccess = {
4560
// Optional keeps call sites clean, but still encourages passing `account?.delegatedAccess`.
4661
delegatedAccess: DelegatedAccess | undefined;
@@ -195,7 +210,7 @@ function connect({email, delegatedAccess, credentials, session, activePolicyID,
195210
})
196211
.then(() => {
197212
NetworkStore.setAuthToken(response?.restrictedToken ?? null);
198-
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
213+
return clearOnyxForDelegateTransition();
199214
})
200215
.then(() => {
201216
confirmReadyToOpenApp();
@@ -294,7 +309,7 @@ function disconnect({stashedCredentials, stashedSession}: DisconnectParams) {
294309
})
295310
.then(() => {
296311
NetworkStore.setAuthToken(response?.authToken ?? null);
297-
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS);
312+
return clearOnyxForDelegateTransition();
298313
})
299314
.then(() => {
300315
Onyx.set(ONYXKEYS.CREDENTIALS, {
@@ -663,7 +678,7 @@ function updateDelegateRole({email, role, validateCode, delegatedAccess}: Update
663678
}
664679

665680
function restoreDelegateSession<TKey extends OnyxKey>(authenticateResponse: Response<TKey>) {
666-
Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS).then(() => {
681+
clearOnyxForDelegateTransition().then(() => {
667682
updateSessionAuthTokens(authenticateResponse?.authToken, authenticateResponse?.encryptedAuthToken);
668683
updateSessionUser(authenticateResponse?.accountID, authenticateResponse?.email);
669684

@@ -690,5 +705,5 @@ export {
690705
updateDelegateRole,
691706
removeDelegate,
692707
openSecuritySettingsPage,
693-
KEYS_TO_PRESERVE_DELEGATE_ACCESS,
708+
clearOnyxForDelegateTransition,
694709
};

src/libs/actions/Session/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Timers from '@libs/Timers';
5151
import {hideContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
5252
import {confirmReadyToOpenApp, KEYS_TO_PRESERVE, openApp} from '@userActions/App';
5353
import {clearCachedAttachments} from '@userActions/Attachment';
54-
import {KEYS_TO_PRESERVE_DELEGATE_ACCESS} from '@userActions/Delegate';
54+
import {clearOnyxForDelegateTransition} from '@userActions/Delegate';
5555
import * as Device from '@userActions/Device';
5656
import type HybridAppSettings from '@userActions/HybridApp/types';
5757
import {close} from '@userActions/Modal';
@@ -718,7 +718,7 @@ function setupNewDotAfterTransitionFromOldDot(hybridAppSettings: HybridAppSettin
718718
}
719719

720720
Log.info('[HybridApp] User switched account on OldDot side. Clearing onyx and applying delegate data');
721-
return Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS)
721+
return clearOnyxForDelegateTransition()
722722
.then(() =>
723723
Onyx.multiSet({
724724
...stashedData,

0 commit comments

Comments
 (0)