import { createClient } from "@/lib/supabase/server"; import { loadProfile } from "@/lib/auth/profile"; import { ladeFirma, type Firma } from "./queries"; export type AdminKontext = { ok: true; firma: Firma; profilId: string } | { ok: false; error: string }; // Rolle aus dem eigenen Profil, Firma ueber den RLS-Client (aktiv + eigene). // Alle Firmen-Actions nehmen die firma_id ausschliesslich von hier, nie aus dem Formular. export async function ladeAdminKontext(): Promise { const profil = await loadProfile(); if (profil.status !== "ok" || profil.profile.role !== "admin" || !profil.profile.firma_id) { return { ok: false, error: "Nur Admins einer Firma dürfen das." }; } const supabase = await createClient(); const firma = await ladeFirma(supabase, profil.profile.firma_id); if (!firma) { return { ok: false, error: "Firma nicht gefunden oder deaktiviert." }; } return { ok: true, firma, profilId: profil.profile.id }; }