fix(rbac): drop X-Tenant-ID short-circuit in SSE / fetch paths
The previous PR removed the "selectedTenantId === weknora_tenant.id → skip header" short-circuit from the axios interceptor, but the same copy-pasted logic lived in three more places that bypass axios: - `api/chat/streame.ts` — `fetchEventSource` for the streaming chat endpoint. Without this fix the chat reply would 404 with "流式连接失败:HTTP 404" on the first message after switching to a non-home tenant: the SSE call landed on the home tenant where the freshly-created session did not exist. - `api/initialization/index.ts` — native `fetch` for multimodal test (FormData) requests. Misroutes the test to the home tenant. - `utils/security.ts` — `getProtectedFileRequestHeaders` used by the Markdown image proxy. Authenticated file fetches landed on the home tenant, breaking image rendering after a tenant switch. All three now mirror the simplified rule: if `weknora_selected_tenant_id` is set, attach `X-Tenant-ID` unconditionally. The server's `IsTenantAccessible` already accepts a header pointing at the user's home tenant, so always attaching is safe. Same root cause as the axios fix: any code path that writes the active tenant into `weknora_tenant` (UserMenu's `loadUserInfo`, OIDC sync, router hydrate) made the two values equal, after which these non-axios paths silently dropped the header and re-routed to home.
This commit is contained in:
@@ -276,17 +276,14 @@ function getProtectedFileRequestHeaders(): Record<string, string> {
|
||||
}
|
||||
|
||||
const selectedTenantId = (localStorage.getItem('weknora_selected_tenant_id') || '').trim();
|
||||
const tenantRaw = localStorage.getItem('weknora_tenant');
|
||||
if (selectedTenantId) {
|
||||
try {
|
||||
const tenant = tenantRaw ? JSON.parse(tenantRaw) : null;
|
||||
const defaultTenantId = tenant?.id ? String(tenant.id) : '';
|
||||
if (selectedTenantId !== defaultTenantId) {
|
||||
headers['X-Tenant-ID'] = selectedTenantId;
|
||||
}
|
||||
} catch {
|
||||
// ignore tenant parse error and skip X-Tenant-ID
|
||||
}
|
||||
// Always attach when a selected tenant is set. Same rationale as
|
||||
// utils/request.ts / api/chat/streame.ts: the
|
||||
// "selectedTenantId === defaultTenantId → skip" short-circuit
|
||||
// silently drops the header whenever any code path writes the
|
||||
// active tenant into weknora_tenant, leaving authenticated file
|
||||
// fetches landing on the home tenant.
|
||||
headers['X-Tenant-ID'] = selectedTenantId;
|
||||
}
|
||||
} catch {
|
||||
// ignore localStorage read errors
|
||||
|
||||
Reference in New Issue
Block a user