251208:1625 Frontend: to be complete admin panel, Backend: tobe recheck all task
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { AdminSidebar } from "@/components/admin/sidebar";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
|
||||
export default async function AdminLayout({
|
||||
@@ -9,16 +8,13 @@ export default async function AdminLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const session = await getServerSession(authOptions);
|
||||
const session = await auth();
|
||||
|
||||
// Check if user has admin role
|
||||
// This depends on your Session structure. Assuming user.roles exists (mapped in callback).
|
||||
// If not, you might need to check DB or use Can component logic but server-side.
|
||||
const isAdmin = session?.user?.roles?.some((r: any) => r.role_name === 'ADMIN');
|
||||
// Temporary bypass for UI testing
|
||||
const isAdmin = true; // session?.user?.role === 'ADMIN';
|
||||
|
||||
if (!session || !isAdmin) {
|
||||
// If not admin, redirect to dashboard or login
|
||||
redirect("/");
|
||||
// redirect("/");
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user