import Link from 'next/link'; import { cookies } from 'next/headers'; import { AdminConsole } from '../../components/admin-console'; type AuditEvent = { id: string; event_type: string; actor_user_id: string | null; target_user_id: string | null; created_at: string; metadata: Record | null }; async function loadAuditEvents(): Promise<{ status: number; events: AuditEvent[] }> { const token = (await cookies()).get('motorsignal_access_token')?.value; if (!token) return { status: 401, events: [] }; const baseUrl = process.env.MOTORSIGNAL_API_BASE_URL ?? 'https://api.motorsignal.app'; try { const response = await fetch(`${baseUrl}/api/v1/admin/audit-events`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }); if (!response.ok) return { status: response.status, events: [] }; return { status: response.status, events: await response.json() as AuditEvent[] }; } catch { return { status: 503, events: [] }; } } export default async function AdminPage() { const result = await loadAuditEvents(); if (result.status === 401) return
Admin console

Sign in required.

Admin tools require an authenticated MotorSignal session.

Sign in
; if (result.status === 403) return
Admin console

Access restricted.

Your account does not have support or admin permissions.

Back to account
; if (result.status !== 200) return
Admin console

Console unavailable.

Audit data could not be loaded. Try again when the API is available.

; return
Admin console

Operations.

Manage users, vehicles, rides, and review recent account activity.

Recent audit events

{result.events.length === 0 ?

No events recorded.

: result.events.map((event) =>
{event.event_type}

{event.actor_user_id ?? 'System'} {event.target_user_id ? `targeted ${event.target_user_id}` : ''}

)}
; }