import Link from "next/link"; import { redirect } from "next/navigation"; import { apiGet } from "@/lib/server-api"; import { fmtDateTime } from "@/lib/format"; import { isRestricted } from "@/lib/access"; import type { AuditLog, Me } from "@/lib/types"; type Search = Promise>; const FILTERS = ["from", "to", "source", "event_type", "success", "target_user_id", "actor_account"]; export default async function AuditPage({ searchParams }: { searchParams: Search }) { const me = await apiGet("/auth/me"); if (isRestricted(me.account)) redirect("/"); const sp = await searchParams; const params = new URLSearchParams(); for (const key of [...FILTERS, "before"]) { const v = sp[key]; if (typeof v === "string" && v) params.set(key, v); } const { logs, next_before } = await apiGet<{ logs: AuditLog[]; next_before: number | null }>(`/audit?${params}`); const value = (key: string) => (typeof sp[key] === "string" ? (sp[key] as string) : ""); const nextParams = new URLSearchParams(params); if (next_before) nextParams.set("before", String(next_before)); return ( <>

Auditoria

{value("target_user_id") && } Limpar
{logs.length === 0 && ( )} {logs.map((l) => ( ))}
Quando Origem Quem Evento Alvo Resultado Detalhes
Nenhum evento encontrado.
{fmtDateTime(l.occurred_at)} {l.source} {l.actor_username ?? l.actor_user_name ?? "—"} {l.event_type} {l.target_user_id ? {l.target_user_name} : "—"} {l.success ? sucesso : falha} {Object.keys(l.details).length > 0 && {JSON.stringify(l.details)}}
{next_before && (

Mais antigos →

)} ); }