const [loading, setLoading] = useState(true)
const [isAdmin, setIsAdmin] = useState(false)
useEffect(() => {
checkAdmin()
}, [])
async function checkAdmin() {
const {
data: { user },
} = await supabase.auth.getUser()
if (!user) {
window.location.href = "/"
return
}
const { data: profile } = await supabase
.from("profiles")
.select("role")
.eq("user_id", user.id)
.single()
if (profile?.role !== "admin") {
window.location.href = "/"
return
}
setIsAdmin(true)
setLoading(false)
}