fix(auth): update logic after deleting an org

1. Redirect to organizations list if the user has orgs
2. Clear organization from preferences so the deleted org isn't the default and they aren't redirected to it
3. Invalidate after redirect so there isn't a flash or invalid org/team
This commit is contained in:
Steven Nguyen committed 2024-04-29 15:33:57 -07:00
1 parent abdb7203a0
commit 59e484eb16
1 file changed
+7 -12
@@ -24,22 +24,17 @@
} else {
await sdk.forConsole.teams.delete($organization.$id);
}
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.ORGANIZATION);
trackEvent(Submit.OrganizationDelete);
const prefs = await sdk.forConsole.account.getPrefs();
const newPrefs = { ...prefs, organization: null };
await sdk.forConsole.account.updatePrefs(newPrefs);
if ($organizationList?.total > 1) {
const account = await sdk.forConsole.account.get();
const teamId =
account.prefs.organization ??
$organizationList.teams[0].$id === $organization.$id
? $organizationList.teams[1].$id
: $organizationList.teams[0].$id;
await goto(`${base}/console/organization-${teamId}`);
await goto(`${base}/console/account/organizations`);
} else {
await goto(`${base}/console/onboarding`);
}
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.ORGANIZATION);
trackEvent(Submit.OrganizationDelete);
showDelete = false;
addNotification({
type: 'success',