Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
683b5e3
Reinitialize Pusher during delegate account transitions
nabi-ebrahimi Jun 11, 2026
b443612
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 15, 2026
a4d0ca5
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 18, 2026
c8f7a40
Set loading state in OnyxUpdateManager test setup
nabi-ebrahimi Jun 18, 2026
31cc67d
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 18, 2026
21a6434
Revert OnyxUpdateManager test setup update
nabi-ebrahimi Jun 18, 2026
706c1b2
Fix OnyxUpdateManager test mock alias mismatch
nabi-ebrahimi Jun 18, 2026
c788fd3
Fixed Prettier
nabi-ebrahimi Jun 18, 2026
ec0629f
Fix OnyxUpdateManager mock alias lint errors
nabi-ebrahimi Jun 18, 2026
076e0dc
Restore stable missing update assertions in OnyxUpdateManager test
nabi-ebrahimi Jun 20, 2026
f1e4611
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 20, 2026
1b10fd6
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 22, 2026
4830e77
Revert OnyxUpdateManager test changes
nabi-ebrahimi Jun 22, 2026
a265436
Break initializePusher User import cycle
nabi-ebrahimi Jun 22, 2026
2793c4e
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 23, 2026
e67cb1a
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 23, 2026
8912ef3
Reinitialize Pusher through AuthScreensInitHandler for delegate switches
nabi-ebrahimi Jun 23, 2026
7fb11b1
Merge remote-tracking branch 'origin/main' into fix/delegate-switch-p…
nabi-ebrahimi Jun 24, 2026
d92f900
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 26, 2026
7ba3428
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 27, 2026
d2ab2d4
Prevent stale Pusher reinitialization during delegate transitions
nabi-ebrahimi Jun 27, 2026
c6cb713
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 29, 2026
5287359
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 30, 2026
5a27506
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 30, 2026
d2d2028
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jun 30, 2026
759fe0e
Merge branch 'main' into fix/delegate-switch-pusher-reinitialization
nabi-ebrahimi Jul 1, 2026
a828d1d
Log missing Pusher reinit handler during delegate transitions
nabi-ebrahimi Jul 1, 2026
56354eb
Log missing Pusher reinitialization handler
nabi-ebrahimi Jul 1, 2026
a70d63b
Fix Log import path in requestPusherReinitialize
nabi-ebrahimi Jul 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Navigation from '@libs/Navigation/Navigation';
import Pusher from '@libs/Pusher';
import PusherConnectionManager from '@libs/PusherConnectionManager';
import {getReportIDFromLink} from '@libs/ReportUtils';
import {registerPusherReinitializeHandler} from '@libs/requestPusherReinitialize';
import type {PusherReinitializeHandlerParams} from '@libs/requestPusherReinitialize';
import * as SessionUtils from '@libs/SessionUtils';
import {endSpan, getSpan, startSpan} from '@libs/telemetry/activeSpans';
import {getSearchParamFromUrl} from '@libs/Url';
Expand Down Expand Up @@ -75,6 +77,23 @@ function AuthScreensInitHandler() {

useReconcileHighContrastIntent();

useEffect(() => {
registerPusherReinitializeHandler(({accountID, email}: PusherReinitializeHandlerParams = {}) => {
const currentAccountID = accountID ?? session?.accountID;
const currentEmail = email ?? session?.email ?? '';

if (currentAccountID === undefined) {
return Promise.resolve();
}

return initializePusher(currentAccountID, currentEmail, () => reportAttributesRef.current);
});

return () => {
registerPusherReinitializeHandler(null);
};
}, [session?.accountID, session?.email]);

useEffect(() => {
if (!Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) {
return;
Expand Down
48 changes: 28 additions & 20 deletions src/libs/actions/Delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Log from '@libs/Log';
import {clearPreservedSearchNavigatorStates} from '@libs/Navigation/AppNavigator/createSplitNavigator/usePreserveNavigatorState';
import * as NetworkStore from '@libs/Network/NetworkStore';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import Pusher from '@libs/Pusher';
import {requestPusherReinitialize} from '@libs/requestPusherReinitialize';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -215,21 +217,24 @@ function connect({email, delegatedAccess, credentials, session, activePolicyID,
})
.then(() => {
NetworkStore.setAuthToken(response?.restrictedToken ?? null);
Pusher.disconnect();
return clearOnyxForDelegateTransition();
})
.then(() => {
return openApp().then(() => {
if (!CONFIG.IS_HYBRID_APP || !policyID) {
return openApp()
.then(() => requestPusherReinitialize({accountID: response.accountID, email: response.email}))
.then(() => {
if (!CONFIG.IS_HYBRID_APP || !policyID) {
return true;
}
HybridAppModule.switchAccount({
newDotCurrentAccountEmail: email,
authToken: restrictedToken,
policyID,
accountID: String(session?.accountID ?? CONST.DEFAULT_NUMBER_ID),
});
return true;
}
HybridAppModule.switchAccount({
newDotCurrentAccountEmail: email,
authToken: restrictedToken,
policyID,
accountID: String(session?.accountID ?? CONST.DEFAULT_NUMBER_ID),
});
return true;
});
});
})
.catch((error) => {
Expand Down Expand Up @@ -313,6 +318,7 @@ function disconnect({stashedCredentials, stashedSession}: DisconnectParams) {
})
.then(() => {
NetworkStore.setAuthToken(response?.authToken ?? null);
Pusher.disconnect();
return clearOnyxForDelegateTransition();
})
.then(() => {
Expand All @@ -322,17 +328,19 @@ function disconnect({stashedCredentials, stashedSession}: DisconnectParams) {
});
Onyx.set(ONYXKEYS.STASHED_CREDENTIALS, {});
Onyx.set(ONYXKEYS.STASHED_SESSION, {});
openApp().then(() => {
if (!CONFIG.IS_HYBRID_APP) {
return;
}
HybridAppModule.switchAccount({
newDotCurrentAccountEmail: requesterEmail,
authToken,
policyID: '',
accountID: '',
openApp()
.then(() => requestPusherReinitialize({accountID: response.requesterID, email: requesterEmail}))
.then(() => {
if (!CONFIG.IS_HYBRID_APP) {
return;
}
HybridAppModule.switchAccount({
newDotCurrentAccountEmail: requesterEmail,
authToken,
policyID: '',
accountID: '',
});
});
});
});
})
.catch((error) => {
Expand Down
26 changes: 26 additions & 0 deletions src/libs/requestPusherReinitialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Log from './Log';

type PusherReinitializeHandlerParams = {
accountID?: number;
email?: string;
};

type PusherReinitializeHandler = (params?: PusherReinitializeHandlerParams) => Promise<void>;

let registeredHandler: PusherReinitializeHandler | null = null;

function registerPusherReinitializeHandler(handler: PusherReinitializeHandler | null) {
registeredHandler = handler;
}

function requestPusherReinitialize(params?: PusherReinitializeHandlerParams): Promise<void> {
if (!registeredHandler) {
Log.warn('[requestPusherReinitialize] No handler registered, skipping Pusher reinitialization', {params});
return Promise.resolve();
}

return registeredHandler(params);
}

export {registerPusherReinitializeHandler, requestPusherReinitialize};
export type {PusherReinitializeHandlerParams};
Loading