fix(tenant): purge memberships on delete and filter stale switcher rows

Cascade soft-delete tenant_members when a workspace is removed so the
tenant switcher no longer shows ghost entries as "#<id>". Also filter
orphaned memberships in /auth/me and switch to another workspace after
delete when one remains.
This commit is contained in:
wizardchen
2026-06-17 10:27:48 +08:00
committed by lyingbug
parent fd5eecb4e3
commit c3cd629da7
4 changed files with 84 additions and 3 deletions
@@ -251,8 +251,16 @@ import {
} from '@/api/tenant/members'
import { useAuthStore } from '@/stores/auth'
import { useI18n } from 'vue-i18n'
import { useRoleLabel, useHomeTenant } from '@/composables/useRoleLabel'
import {
navigateAfterTenantSwitch,
persistLastActiveTenantPreference,
stashTenantSwitchToast,
} from '@/utils/tenantSwitch'
const { t, locale } = useI18n()
const { formatRole } = useRoleLabel()
const { homeTenantId } = useHomeTenant()
const authStore = useAuthStore()
// Reactive state
@@ -380,6 +388,30 @@ async function deleteCurrentTenant() {
const resp = await deleteTenantApi(tid)
if (resp.success) {
MessagePlugin.success(t('tenant.deleteDangerZone.success'))
authStore.setMemberships(
(authStore.memberships ?? []).filter((m) => m.tenant_id !== tid),
)
await authStore.refreshFromAuthMe()
const next =
authStore.memberships.find((m) => m.tenant_id === homeTenantId.value) ??
authStore.memberships[0]
if (next) {
const switchingToHome =
homeTenantId.value !== null && homeTenantId.value === next.tenant_id
const name = next.tenant_name?.trim() || `#${next.tenant_id}`
authStore.setSelectedTenant(next.tenant_id, name)
stashTenantSwitchToast({
name,
role: formatRole(next.role) || undefined,
roleEnum: next.role || undefined,
})
const persist = persistLastActiveTenantPreference(
switchingToHome ? null : next.tenant_id,
)
await Promise.race([persist, new Promise((r) => setTimeout(r, 400))])
navigateAfterTenantSwitch()
return
}
authStore.logout()
window.location.href = '/login'
} else {