Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear policies after sign out #47776

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,13 @@ function getAdminPoliciesConnectedToNetSuite(): Policy[] {
return Object.values(allPolicies ?? {}).filter<Policy>((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,
Expand Down Expand Up @@ -3464,6 +3471,7 @@ export {
getAdminPoliciesConnectedToNetSuite,
getAdminPoliciesConnectedToSageIntacct,
hasInvoicingDetails,
clearAllPolicies,
enablePolicyRules,
};

Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/SignInRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -29,6 +30,7 @@ function clearStorageAndRedirect(errorMessage?: string): Promise<void> {
}

return Onyx.clear(keysToPreserve).then(() => {
Policy.clearAllPolicies();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the placement for the method is fine here, but I have never touched this part of the code, so I am not sure if we have any preference here.

Will defer to @yuwenmemon for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me

if (!errorMessage) {
return;
}
Expand Down
Loading