1
0
Fork 0
fahrPool/web/lib/firma/eigene-firma.ts

24 lines
996 B
TypeScript

import { cache } from "react";
import { createClient } from "@/lib/supabase/server";
import { loadProfile } from "@/lib/auth/profile";
import { ladeFirma, type Firma } from "./queries";
export const FIRMA_GESPERRT = "Ihre Firma ist deaktiviert oder Ihr Zugang ist keiner Firma zugeordnet.";
export type EigeneFirmaResult =
| { status: "unauthenticated" }
| { status: "missing-profile" }
| { status: "superadmin" }
| { status: "keine-firma" }
| { status: "ok"; firma: Firma };
export const ladeEigeneFirma = cache(async (): Promise<EigeneFirmaResult> => {
const profil = await loadProfile();
if (profil.status !== "ok") return { status: profil.status };
if (profil.profile.role === "superadmin") return { status: "superadmin" };
if (!profil.profile.firma_id) return { status: "keine-firma" };
const supabase = await createClient();
const firma = await ladeFirma(supabase, profil.profile.firma_id);
return firma ? { status: "ok", firma } : { status: "keine-firma" };
});