From 1dd0bcc6663615f805511f1404ba9f2c32f036ff Mon Sep 17 00:00:00 2001 From: ijmalik Date: Sat, 15 Feb 2025 09:16:05 +0500 Subject: [PATCH 1/2] resolve Copilot account stuck issue when user is removed by another user --- src/Expensify.tsx | 11 +++++++++++ src/libs/actions/Delegate.ts | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 1d0100add00f..661ff329498a 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'; @@ -237,6 +238,16 @@ function Expensify() { setCrashlyticsUserId(session?.accountID ?? -1); }, [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; } From 01bae5c3d4770080e3a579382b7b690bf0ce5189 Mon Sep 17 00:00:00 2001 From: ijmalik Date: Mon, 17 Feb 2025 09:41:42 +0500 Subject: [PATCH 2/2] resolve lint error - Default the number ID to CONST.DEFAULT_NUMBER_ID --- src/Expensify.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 661ff329498a..b6d6d0f0cbcc 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -235,7 +235,7 @@ function Expensify() { if (!isAuthenticated) { return; } - setCrashlyticsUserId(session?.accountID ?? -1); + setCrashlyticsUserId(session?.accountID ?? CONST.DEFAULT_NUMBER_ID); }, [isAuthenticated, session?.accountID]); useEffect(() => {