From 59e484eb165405e7d76e895873096d05e45187b0 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 26 Apr 2024 15:46:56 -0700 Subject: [PATCH] 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 --- .../settings/deleteOrganizationModal.svelte | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/routes/console/organization-[organization]/settings/deleteOrganizationModal.svelte b/src/routes/console/organization-[organization]/settings/deleteOrganizationModal.svelte index 48f168cd4..f071e6108 100644 --- a/src/routes/console/organization-[organization]/settings/deleteOrganizationModal.svelte +++ b/src/routes/console/organization-[organization]/settings/deleteOrganizationModal.svelte @@ -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',