Expose machine context debug info in console

This commit is contained in:
Esdras Renan 2025-10-14 19:01:21 -03:00
parent 0fb95147f4
commit a1bd3bb7b9

View file

@ -43,6 +43,12 @@ type MachineContextError = {
details?: Record<string, unknown> | null
}
declare global {
interface Window {
__machineContextDebug?: unknown
}
}
const authClient = createAuthClient({
plugins: [customSessionClient<AppAuth>()],
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,