ClauseGuard / web /lib /admin-guard.ts
gaurv007's picture
v3.0: Fix admin-guard.ts — remove hardcoded email, check DB role only
3d6bc12 verified
raw
history blame
572 Bytes
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 };
}