diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsx index 2ed2854..e152423 100644 --- a/apps/desktop/src/main.tsx +++ b/apps/desktop/src/main.tsx @@ -444,20 +444,20 @@ function App() { if (!res.ok) { // Fallback para o handshake por redirecionamento const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator" - const redirectTarget = persona === "manager" ? "/dashboard" : "/portal" + const redirectTarget = persona === "manager" ? "/dashboard" : "/portal/debug" const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}` window.location.href = url return } } catch { const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator" - const redirectTarget = persona === "manager" ? "/dashboard" : "/portal" + const redirectTarget = persona === "manager" ? "/dashboard" : "/portal/debug" const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}` window.location.href = url return } const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator" - const redirectTarget = persona === "manager" ? "/dashboard" : "/portal" + const redirectTarget = persona === "manager" ? "/dashboard" : "/portal/debug" window.location.href = `${resolvedAppUrl}${redirectTarget}` }, [token, config?.accessRole, accessRole, resolvedAppUrl, apiBaseUrl]) diff --git a/src/app/portal/debug/page.tsx b/src/app/portal/debug/page.tsx new file mode 100644 index 0000000..8525691 --- /dev/null +++ b/src/app/portal/debug/page.tsx @@ -0,0 +1,65 @@ +"use client" + +import { useEffect, useState } from "react" + +type Json = Record | null + +export default function PortalDebugPage() { + const [authSession, setAuthSession] = useState(null) + const [authStatus, setAuthStatus] = useState(null) + const [machine, setMachine] = useState(null) + const [machineStatus, setMachineStatus] = useState(null) + const [error, setError] = useState(null) + + useEffect(() => { + let cancelled = false + ;(async () => { + try { + const a = await fetch("/api/auth/get-session", { credentials: "include" }) + const aBody = await a.json().catch(() => null) + if (!cancelled) { + setAuthStatus(a.status) + setAuthSession(aBody as Json) + } + + const m = await fetch("/api/machines/session", { credentials: "include" }) + const mBody = await m.json().catch(() => null) + if (!cancelled) { + setMachineStatus(m.status) + setMachine(mBody as Json) + } + } catch (err) { + if (!cancelled) setError(err instanceof Error ? err.message : String(err)) + } + })() + return () => { cancelled = true } + }, []) + + return ( +
+

Diagnóstico de sessão

+

Esta página consulta a API com os mesmos cookies desta aba.

+ + {error ? ( +
{error}
+ ) : null} + +
+

/api/auth/get-session

+
status: {authStatus ?? "—"}
+
{JSON.stringify(authSession, null, 2)}
+
+ +
+

/api/machines/session

+
status: {machineStatus ?? "—"}
+
{JSON.stringify(machine, null, 2)}
+
+ +
+ Se algum status for 401/403, os cookies de sessão não estão válidos. Reabra o agente e tente novamente. +
+
+ ) +} +