This repository has been archived on 2026-05-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
app/apps/web/src/lib/devFetch.ts
T
groombook-engineer[bot] 321bd90249 fix(web): remove early-return guard from devFetch interceptor (GRO-406)
The if (!getDevUser()) return at install time prevented the interceptor
from installing on app startup before any dev user was selected. Since
the per-call check already handles the no-dev-user case correctly,
the early-return guard is unnecessary and breaks the interceptor install
in deployed dev builds.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-02 19:24:54 +00:00

29 lines
952 B
TypeScript

import { getDevUser } from "../pages/DevLoginSelector.js";
const originalFetch = window.fetch;
/**
* Patches global fetch to include X-Dev-User-Id header on API requests
* when a dev user is selected via the login selector.
*
* Intentionally mutates window.fetch — this is dev-only (AUTH_DISABLED=true).
*/
export function installDevFetchInterceptor() {
window.fetch = function (input: RequestInfo | URL, init?: RequestInit) {
const user = getDevUser();
if (!user) return originalFetch(input, init);
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
// Only inject header for API calls
if (!url.startsWith("/api/")) return originalFetch(input, init);
const headers = new Headers(init?.headers);
if (!headers.has("X-Dev-User-Id")) {
headers.set("X-Dev-User-Id", user.id);
}
return originalFetch(input, { ...init, headers });
};
}