Improve dev logs on login

Enable ApiDevTools to reliably log API requests on login by refining fetch interception (only log /api/* calls, support dev mode), and adjust login error handling to surface dev-friendly messages.

X-Lovable-Edit-ID: edt-f0cc8901-1c2f-4253-819a-332460757b44
This commit is contained in:
gpt-engineer-app[bot]
2026-01-11 05:52:19 +00:00
+24 -8
View File
@@ -46,15 +46,30 @@ function clearLogs() {
notifyListeners(); notifyListeners();
} }
// Intercept fetch // Intercept fetch (dev only)
const isDev = import.meta.env.DEV;
const originalFetch = window.fetch; const originalFetch = window.fetch;
window.fetch = async function (input, init) {
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; // Avoid patching multiple times during HMR
const globalAny = window as unknown as { __gatehouseFetchPatched?: boolean };
// Only log API calls if (isDev && !globalAny.__gatehouseFetchPatched) {
if (!url.includes("/api/")) { globalAny.__gatehouseFetchPatched = true;
return originalFetch.apply(this, [input, init]);
} window.fetch = async function (input, init) {
const url =
typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
// Log calls that look like our backend API (support both absolute + relative base URLs)
const shouldLog =
url.includes("/api/") ||
url.includes("/api/v1") ||
url.includes("/auth/") ||
url.includes("/users/") ||
url.includes("/org/");
if (!shouldLog) {
return originalFetch.apply(this, [input, init]);
}
const id = crypto.randomUUID(); const id = crypto.randomUUID();
const method = init?.method || "GET"; const method = init?.method || "GET";
@@ -133,6 +148,7 @@ window.fetch = async function (input, init) {
throw err; throw err;
} }
}; };
}
// Check if we're in development mode // Check if we're in development mode
const isDev = import.meta.env.DEV; const isDev = import.meta.env.DEV;