Spaces:
Sleeping
Sleeping
| import { createClient } from "@/lib/supabase/server"; | |
| import { redirect } from "next/navigation"; | |
| export async function requireAdmin() { | |
| const supabase = await createClient(); | |
| const { data: { user } } = await supabase.auth.getUser(); | |
| if (!user) redirect("/auth/login"); | |
| // Check role from database — no hardcoded emails | |
| const { data: profile } = await supabase | |
| .from("profiles") | |
| .select("role") | |
| .eq("id", user.id) | |
| .single(); | |
| if (profile?.role !== "admin") { | |
| redirect("/dashboard-pages/dashboard"); | |
| } | |
| return { user, supabase }; | |
| } | |