File size: 1,017 Bytes
8ec33d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { supabase } from "@/integrations/supabase/client";
import { useQuery } from "@tanstack/react-query";
import { AdminHighScoresTable } from "@/components/admin/AdminHighScoresTable";
export const AdminIndex = () => {
const navigate = useNavigate();
useEffect(() => {
const checkAdmin = async () => {
const { data: { user } } = await supabase.auth.getUser();
if (!user) {
navigate("/admin/login");
return;
}
const { data: isAdmin, error } = await supabase.rpc('is_admin', {
user_id: user.id
});
if (error || !isAdmin) {
console.error("Not an admin or error checking admin status:", error);
navigate("/admin/login");
}
};
checkAdmin();
}, [navigate]);
return (
<div className="container mx-auto py-8">
<h1 className="text-2xl font-bold mb-6">Admin Dashboard</h1>
<AdminHighScoresTable />
</div>
);
}; |