Add /portal/debug page and navigate there after session; shows auth + machine context
This commit is contained in:
parent
6754af769b
commit
1e850ed11e
2 changed files with 68 additions and 3 deletions
|
|
@ -444,20 +444,20 @@ function App() {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// Fallback para o handshake por redirecionamento
|
// Fallback para o handshake por redirecionamento
|
||||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
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)}`
|
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}`
|
||||||
window.location.href = url
|
window.location.href = url
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
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)}`
|
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}`
|
||||||
window.location.href = url
|
window.location.href = url
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
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}`
|
window.location.href = `${resolvedAppUrl}${redirectTarget}`
|
||||||
}, [token, config?.accessRole, accessRole, resolvedAppUrl, apiBaseUrl])
|
}, [token, config?.accessRole, accessRole, resolvedAppUrl, apiBaseUrl])
|
||||||
|
|
||||||
|
|
|
||||||
65
src/app/portal/debug/page.tsx
Normal file
65
src/app/portal/debug/page.tsx
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
type Json = Record<string, unknown> | null
|
||||||
|
|
||||||
|
export default function PortalDebugPage() {
|
||||||
|
const [authSession, setAuthSession] = useState<Json>(null)
|
||||||
|
const [authStatus, setAuthStatus] = useState<number | null>(null)
|
||||||
|
const [machine, setMachine] = useState<Json>(null)
|
||||||
|
const [machineStatus, setMachineStatus] = useState<number | null>(null)
|
||||||
|
const [error, setError] = useState<string | null>(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 (
|
||||||
|
<div className="mx-auto max-w-3xl space-y-4 p-6">
|
||||||
|
<h1 className="text-lg font-semibold">Diagnóstico de sessão</h1>
|
||||||
|
<p className="text-sm text-neutral-600">Esta página consulta a API com os mesmos cookies desta aba.</p>
|
||||||
|
|
||||||
|
{error ? (
|
||||||
|
<div className="rounded-md border border-rose-200 bg-rose-50 p-3 text-sm text-rose-700">{error}</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<section className="rounded-md border border-slate-200 bg-white p-4">
|
||||||
|
<h2 className="mb-2 text-sm font-semibold">/api/auth/get-session</h2>
|
||||||
|
<div className="mb-2 text-xs text-neutral-500">status: {authStatus ?? "—"}</div>
|
||||||
|
<pre className="overflow-x-auto rounded-md bg-slate-50 p-3 text-xs leading-tight">{JSON.stringify(authSession, null, 2)}</pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="rounded-md border border-slate-200 bg-white p-4">
|
||||||
|
<h2 className="mb-2 text-sm font-semibold">/api/machines/session</h2>
|
||||||
|
<div className="mb-2 text-xs text-neutral-500">status: {machineStatus ?? "—"}</div>
|
||||||
|
<pre className="overflow-x-auto rounded-md bg-slate-50 p-3 text-xs leading-tight">{JSON.stringify(machine, null, 2)}</pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div className="text-xs text-neutral-500">
|
||||||
|
Se algum status for 401/403, os cookies de sessão não estão válidos. Reabra o agente e tente novamente.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue