import { redirect } from "next/navigation"; import { createAuftrag } from "./actions"; import { listOrte, listFahrzeuge } from "@/lib/auftraege/queries"; import { loadProfile } from "@/lib/auth/profile"; export default async function NeuerAuftragPage({ searchParams, }: { searchParams: Promise<{ error?: string; vorgaenger_auftrag_id?: string }>; }) { const profileResult = await loadProfile(); // Seitenebenen-Gate zusaetzlich zur INSERT-RLS-Policy auf `auftraege` // (admin/disponent-only): ohne diesen Check wuerde die Seite das Formular // auch Fahrern/Readonly anzeigen, obwohl ein Submit dann ohnehin an der // RLS-Policy scheitern wuerde -- das ist verwirrend UX statt eines echten // Sicherheitslecks, aber ein frueher Redirect ist die klarere Loesung. if ( profileResult.status !== "ok" || (profileResult.profile.role !== "admin" && profileResult.profile.role !== "disponent") ) { redirect(`/auftraege?error=${encodeURIComponent("Nur Disponent/Admin duerfen Auftraege anlegen.")}`); } const { error, vorgaenger_auftrag_id } = await searchParams; const [orte, fahrzeuge] = await Promise.all([listOrte(), listFahrzeuge()]); return (

Neuen Auftrag anlegen

{error &&

{error}

}
{vorgaenger_auftrag_id && ( )}
); }