fix(api,web): add workspace context to widgets and auto-detect workspace ID (#532)
All checks were successful
ci/woodpecker/push/web Pipeline was successful
ci/woodpecker/push/api Pipeline was successful

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #532.
This commit is contained in:
2026-02-27 04:53:07 +00:00
committed by jason.woltje
parent e3cba37e8c
commit edcff6a0e0
4 changed files with 43 additions and 62 deletions

View File

@@ -202,9 +202,13 @@ export async function apiRequest<T>(endpoint: string, options: ApiRequestOptions
...baseHeaders,
};
// Add workspace ID header if provided (recommended over query string)
if (workspaceId) {
headers["X-Workspace-Id"] = workspaceId;
// Add workspace ID header — use explicit value, or auto-detect from localStorage
const resolvedWorkspaceId =
workspaceId ??
(typeof window !== "undefined" ? localStorage.getItem("mosaic-workspace-id") : null) ??
undefined;
if (resolvedWorkspaceId) {
headers["X-Workspace-Id"] = resolvedWorkspaceId;
}
// Add CSRF token for state-changing requests (POST, PUT, PATCH, DELETE)