diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 1d0100add00f..b6d6d0f0cbcc 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -17,6 +17,7 @@ import * as CONFIG from './CONFIG'; import CONST from './CONST'; import useLocalize from './hooks/useLocalize'; import {updateLastRoute} from './libs/actions/App'; +import {disconnect} from './libs/actions/Delegate'; import * as EmojiPickerAction from './libs/actions/EmojiPickerAction'; import * as Report from './libs/actions/Report'; import * as User from './libs/actions/User'; @@ -234,9 +235,19 @@ function Expensify() { if (!isAuthenticated) { return; } - setCrashlyticsUserId(session?.accountID ?? -1); + setCrashlyticsUserId(session?.accountID ?? CONST.DEFAULT_NUMBER_ID); }, [isAuthenticated, session?.accountID]); + useEffect(() => { + if (!account?.delegatedAccess?.delegate) { + return; + } + if (account?.delegatedAccess?.delegates?.some((d) => d.email === account?.delegatedAccess?.delegate)) { + return; + } + disconnect(); + }, [account?.delegatedAccess?.delegates, account?.delegatedAccess?.delegate]); + // Display a blank page until the onyx migration completes if (!isOnyxMigrated) { return null; diff --git a/src/libs/actions/Delegate.ts b/src/libs/actions/Delegate.ts index 8e6d73053f10..e955b69ec7ab 100644 --- a/src/libs/actions/Delegate.ts +++ b/src/libs/actions/Delegate.ts @@ -209,11 +209,13 @@ function disconnect() { .then((response) => { if (!response?.authToken || !response?.encryptedAuthToken) { Log.alert('[Delegate] No auth token returned while disconnecting as a delegate'); + restoreDelegateSession(stashedSession); return; } if (!response?.requesterID || !response?.requesterEmail) { Log.alert('[Delegate] No requester data returned while disconnecting as a delegate'); + restoreDelegateSession(stashedSession); return; }