gaurv007 commited on
Commit
efd3fc1
·
verified ·
1 Parent(s): f9d1091

v3.0: Fix nav.tsx — remove hardcoded ADMIN_EMAILS, fetch role from DB profile

Browse files
Files changed (1) hide show
  1. web/components/nav.tsx +14 -5
web/components/nav.tsx CHANGED
@@ -13,19 +13,28 @@ const links = [
13
  { href: "/dashboard-pages/compare", label: "Compare", icon: GitCompare },
14
  ];
15
 
16
- const ADMIN_EMAILS = ["ankygaur9972@gmail.com"];
17
-
18
  export function Nav() {
19
  const [open, setOpen] = useState(false);
20
  const [userEmail, setUserEmail] = useState<string | null>(null);
 
21
  const pathname = usePathname();
22
  const isDashboard = pathname?.startsWith("/dashboard");
23
- const isAdmin = userEmail && ADMIN_EMAILS.includes(userEmail);
24
 
25
  useEffect(() => {
26
  const supabase = createClient();
27
- supabase.auth.getUser().then(({ data }) => {
28
- setUserEmail(data.user?.email || null);
 
 
 
 
 
 
 
 
 
 
29
  });
30
  }, []);
31
 
 
13
  { href: "/dashboard-pages/compare", label: "Compare", icon: GitCompare },
14
  ];
15
 
 
 
16
  export function Nav() {
17
  const [open, setOpen] = useState(false);
18
  const [userEmail, setUserEmail] = useState<string | null>(null);
19
+ const [userRole, setUserRole] = useState<string | null>(null);
20
  const pathname = usePathname();
21
  const isDashboard = pathname?.startsWith("/dashboard");
22
+ const isAdmin = userRole === "admin";
23
 
24
  useEffect(() => {
25
  const supabase = createClient();
26
+ supabase.auth.getUser().then(async ({ data }) => {
27
+ const user = data.user;
28
+ setUserEmail(user?.email || null);
29
+ if (user) {
30
+ // Fetch role from database — no hardcoded emails
31
+ const { data: profile } = await supabase
32
+ .from("profiles")
33
+ .select("role")
34
+ .eq("id", user.id)
35
+ .single();
36
+ setUserRole(profile?.role || "user");
37
+ }
38
  });
39
  }, []);
40