From a1bd3bb7b9ccaa56151740a895083e87dc758fa2 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Tue, 14 Oct 2025 19:01:21 -0300 Subject: [PATCH] Expose machine context debug info in console --- src/lib/auth-client.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib/auth-client.tsx b/src/lib/auth-client.tsx index 9456ac6..5d1490c 100644 --- a/src/lib/auth-client.tsx +++ b/src/lib/auth-client.tsx @@ -43,6 +43,12 @@ type MachineContextError = { details?: Record | null } +declare global { + interface Window { + __machineContextDebug?: unknown + } +} + const authClient = createAuthClient({ plugins: [customSessionClient()], fetchOptions: { @@ -124,6 +130,16 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { const message = (payload && typeof payload.error === "string" && payload.error.trim()) || fallbackMessage if (!cancelled) { + const debugPayload = { + status: response.status, + message, + payload, + timestamp: new Date().toISOString(), + } + console.error("[auth] machine context request failed", debugPayload) + if (typeof window !== "undefined") { + window.__machineContextDebug = debugPayload + } setMachineContext(null) setMachineContextError({ status: response.status, @@ -160,6 +176,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { } catch (error) { console.error("Failed to load machine context", error) if (!cancelled) { + const debugPayload = { + error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : String(error), + timestamp: new Date().toISOString(), + } + console.error("[auth] machine context unexpected error", debugPayload) + if (typeof window !== "undefined") { + window.__machineContextDebug = debugPayload + } setMachineContext(null) setMachineContextError({ status: 0,