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:
@@ -435,19 +435,12 @@ export function testMultimodalFunction(testData: {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
// 添加跨租户访问请求头(如果选择了其他租户)
|
||||
// 跨租户访问请求头:直接附,避免 short-circuit "selectedTenantId
|
||||
// === defaultTenantId 时不附" 在某些边角下让 header 静默丢失。
|
||||
// 与 utils/request.ts、api/chat/streame.ts 行为一致。
|
||||
const selectedTenantId = localStorage.getItem('weknora_selected_tenant_id');
|
||||
const defaultTenantId = localStorage.getItem('weknora_tenant');
|
||||
if (selectedTenantId) {
|
||||
try {
|
||||
const defaultTenant = defaultTenantId ? JSON.parse(defaultTenantId) : null;
|
||||
const defaultId = defaultTenant?.id ? String(defaultTenant.id) : null;
|
||||
if (selectedTenantId !== defaultId) {
|
||||
headers['X-Tenant-ID'] = selectedTenantId;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse tenant info', e);
|
||||
}
|
||||
headers['X-Tenant-ID'] = selectedTenantId;
|
||||
}
|
||||
|
||||
// 使用原生fetch因为需要发送FormData
|
||||
|
||||
Reference in New Issue
Block a user