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
+21 -5
View File
@@ -46,13 +46,28 @@ 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;
// Only log API calls // Avoid patching multiple times during HMR
if (!url.includes("/api/")) { const globalAny = window as unknown as { __gatehouseFetchPatched?: boolean };
if (isDev && !globalAny.__gatehouseFetchPatched) {
globalAny.__gatehouseFetchPatched = true;
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]); return originalFetch.apply(this, [input, init]);
} }
@@ -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;