feat(ui): redirect tenant switch away from tenant-scoped routes
Switching the active tenant triggers window.location.reload() to re-key every cached store / open SSE stream / in-flight request. The catch: when the user is currently sitting on a route whose URL embeds a tenant-scoped resource id, the new tenant lands on a 404/403 and the user sees a blank screen. Three risky route shapes today: /platform/knowledge-bases/:kbId /platform/knowledge-bases/:kbId/creatChat /platform/chat/:chatid Add a tiny tenantSwitch utility (navigateAfterTenantSwitch) that matches the current path against this list and redirects to /platform/knowledge-bases — the platform default landing, always renderable regardless of role. Anything else (settings, agent list, KB list, etc.) continues to reload its current path because those views handle empty/forbidden data gracefully. Both tenant-switch call sites (TenantSelector and UserMenu) use the helper so the matrix lives in one place; future tenant-scoped routes only need to add a regex to the list.
This commit is contained in:
@@ -214,6 +214,7 @@ import { getCurrentUser, logout as logoutApi } from '@/api/auth'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import IMChannelsOverviewPanel from '@/components/IMChannelsOverviewPanel.vue'
|
||||
import { listAllIMChannels, type IMChannelOverview } from '@/api/agent'
|
||||
import { navigateAfterTenantSwitch } from '@/utils/tenantSwitch'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -372,10 +373,12 @@ const switchToTenant = (m: Membership) => {
|
||||
closeAll()
|
||||
MessagePlugin.success(t('tenant.switchSuccess'))
|
||||
// Hard reload so every cached store / open SSE stream / in-flight
|
||||
// request gets re-keyed under the new tenant. Same approach as
|
||||
// TenantSelector.vue.
|
||||
// request gets re-keyed under the new tenant. If the current path
|
||||
// embeds a tenant-scoped resource id, reload would white-screen the
|
||||
// user; navigateAfterTenantSwitch redirects to the platform home in
|
||||
// that case. Same helper as TenantSelector.vue.
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
navigateAfterTenantSwitch()
|
||||
}, 400)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user