From e4114ec83a6a2f2d4120ceded1a3cd11cc44521c Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 21 Aug 2024 16:10:34 +0700 Subject: [PATCH] fix: clear policies after sign out --- src/libs/actions/Policy/Policy.ts | 8 ++++++++ src/libs/actions/SignInRedirect.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index d0913a2b0ac1..918601a934a4 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3291,6 +3291,13 @@ function getAdminPoliciesConnectedToNetSuite(): Policy[] { return Object.values(allPolicies ?? {}).filter((policy): policy is Policy => !!policy && policy.role === CONST.POLICY.ROLE.ADMIN && !!policy?.connections?.netsuite); } +function clearAllPolicies() { + if (!allPolicies) { + return; + } + Object.keys(allPolicies).forEach((key) => delete allPolicies[key]); +} + export { leaveWorkspace, addBillingCardAndRequestPolicyOwnerChange, @@ -3367,6 +3374,7 @@ export { getAdminPoliciesConnectedToNetSuite, getAdminPoliciesConnectedToSageIntacct, hasInvoicingDetails, + clearAllPolicies, }; export type {NewCustomUnit}; diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index e72a4b011074..4d8b60265f29 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx'; import * as ErrorUtils from '@libs/ErrorUtils'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; +import * as Policy from './Policy/Policy'; let currentIsOffline: boolean | undefined; let currentShouldForceOffline: boolean | undefined; @@ -29,6 +30,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { } return Onyx.clear(keysToPreserve).then(() => { + Policy.clearAllPolicies(); if (!errorMessage) { return; }