60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import { createClient } from "@/lib/supabase/server";
|
|
|
|
export default async function AdminLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const supabase = await createClient();
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
if (!user) redirect("/login");
|
|
|
|
const { data: profile } = await supabase
|
|
.from("profiles")
|
|
.select("role, full_name")
|
|
.eq("id", user.id)
|
|
.single();
|
|
if (profile?.role !== "admin") redirect("/intern");
|
|
|
|
return (
|
|
<div className="flex-1 flex flex-col">
|
|
<header className="bg-[var(--c-primary-dark)] text-white">
|
|
<div className="max-w-[1600px] mx-auto w-full px-4 py-3 flex flex-wrap items-center gap-x-5 gap-y-2">
|
|
<span className="font-bold">Verwaltung</span>
|
|
<nav className="flex flex-wrap gap-x-4 gap-y-1 text-sm">
|
|
<Link href="/admin" className="hover:underline">
|
|
Benutzer
|
|
</Link>
|
|
<Link href="/admin/design" className="hover:underline">
|
|
Design
|
|
</Link>
|
|
<Link href="/intern" className="hover:underline">
|
|
Kantinen-Bereich
|
|
</Link>
|
|
<Link href="/" className="hover:underline">
|
|
Zur Speisekarte
|
|
</Link>
|
|
</nav>
|
|
<div className="ml-auto flex items-center gap-3 text-sm">
|
|
<span className="text-white/70">
|
|
{profile.full_name || user.email}
|
|
</span>
|
|
<form action="/logout" method="post">
|
|
<button type="submit" className="btn btn-del">
|
|
Abmelden
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<main className="max-w-[1600px] mx-auto w-full px-4 py-6 flex-1">
|
|
{children}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|