fix: allow owner role to access admin pages

This commit is contained in:
dyzulk
2025-12-30 20:14:39 +07:00
parent e64df76835
commit e7c02d5fa1
8 changed files with 63 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
"use client";
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/hooks/useAuth";
import useSWR from "swr";
import axios from "@/lib/axios";
import { Plus, Search, FileText, ChevronRight, Edit3, Trash2 } from "lucide-react";
@@ -15,7 +17,16 @@ const fetcher = (url: string) => axios.get(url).then((res) => res.data);
export default function AdminLegalListClient() {
const t = useTranslations("LegalAdmin");
const router = useRouter();
const { user, isAdminOrOwner } = useAuth();
const { addToast } = useToast();
useEffect(() => {
if (user && !isAdminOrOwner) {
router.push("/dashboard");
}
}, [user, isAdminOrOwner, router]);
const [searchTerm, setSearchTerm] = useState("");
const { data, mutate, isLoading } = useSWR("/api/admin/legal-pages", fetcher);