From f3f0dca3e51e897a1588767030155eb8f5529c9e Mon Sep 17 00:00:00 2001 From: RKWojs Date: Mon, 12 Jan 2026 12:33:10 +0100 Subject: [PATCH] feat: create admin page with session management and access control --- src/app/admin/page.js | 136 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/app/admin/page.js diff --git a/src/app/admin/page.js b/src/app/admin/page.js new file mode 100644 index 0000000..9ae4eb3 --- /dev/null +++ b/src/app/admin/page.js @@ -0,0 +1,136 @@ +"use client"; + +import { useSession } from "next-auth/react"; +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; +import Link from "next/link"; + +export default function AdminPage() { + const { data: session, status } = useSession(); + const router = useRouter(); + + useEffect(() => { + if (status === "loading") return; + if (!session || session.user.role !== "admin") { + router.push("/"); + } + }, [session, status, router]); + + if (status === "loading") { + return ( +
+
Loading...
+
+ ); + } + + if (!session || session.user.role !== "admin") { + return ( +
+
+

+ Access Denied +

+

+ You need admin privileges to access this page. +

+ + Go Home + +
+
+ ); + } + + const adminPages = [ + { + title: "Users", + description: "Manage user accounts, roles, and permissions", + href: "/admin/users", + icon: "👥", + color: "bg-blue-500 hover:bg-blue-600", + }, + { + title: "Settings", + description: "Configure system settings, backups, and cron jobs", + href: "/admin/settings", + icon: "⚙️", + color: "bg-gray-600 hover:bg-gray-700", + }, + { + title: "Audit Logs", + description: "View system activity and audit trail", + href: "/admin/audit-logs", + icon: "📋", + color: "bg-purple-500 hover:bg-purple-600", + }, + ]; + + return ( +
+
+
+
+
+

+ Admin Panel +

+

+ Manage your application settings and users +

+
+ + ← Back to Dashboard + +
+
+ +
+ {adminPages.map((page) => ( + +
{page.icon}
+

{page.title}

+

{page.description}

+ + ))} +
+ +
+

+ Quick Info +

+
+
+
Logged in as
+
+ {session.user.name} +
+
+
+
Role
+
+ {session.user.role} +
+
+
+
Environment
+
+ {process.env.NODE_ENV || "development"} +
+
+
+
+
+
+ ); +}