"use client"; import React, { useState, useEffect } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useSession } from "next-auth/react"; import { getDemoStore } from "@/lib/mockData"; interface AdminUser { id: string; name: string; email: string; role: "USER" | "ADMIN"; createdAt: string; taskCount: number; active: boolean; } const INITIAL_ADMIN_USERS: AdminUser[] = [ { id: "user-1", name: "Admin Master", email: "admin@checkflow.local", role: "ADMIN", createdAt: "2026-08-01T09:00:00Z", taskCount: 42, active: true, }, { id: "user-2", name: "Demo Explorer", email: "demo@checkflow.local", role: "USER", createdAt: "2026-08-15T14:20:00Z", taskCount: 18, active: true, }, { id: "user-3", name: "Family Member 1", email: "sarah@home.lan", role: "USER", createdAt: "2026-08-18T11:00:00Z", taskCount: 7, active: true, }, ]; export default function AdminPage() { const router = useRouter(); const { data: session, status } = useSession(); const [users, setUsers] = useState(INITIAL_ADMIN_USERS); const [search, setSearch] = useState(""); const [totalTasks] = useState(() => { if (typeof window !== "undefined") { const store = getDemoStore(); return store.tasks ? store.tasks.length : 67; } return 67; }); const [totalLists] = useState(() => { if (typeof window !== "undefined") { const store = getDemoStore(); return store.lists ? store.lists.length : 9; } return 9; }); // 어드민 권한 판별 const userRole = session?.user?.role; const userEmail = session?.user?.email; const isAdmin = userRole === "ADMIN" || userEmail?.endsWith("@checkflow.local") || userEmail?.startsWith("admin@"); // 인증 게이트: 비로그인 시 /login으로 리디렉션 useEffect(() => { if (status === "unauthenticated") { router.replace("/login?callbackUrl=/admin"); } }, [status, router]); // 로딩 중 스피너 if (status === "loading" || status === "unauthenticated") { return (
🔒

Checking administrator credentials...

); } // 비인가 사용자(일반 유저) 차단 화면 if (!isAdmin) { return (
🛡️

Access Restricted

This console requires ADMIN privileges. Your account ({session?.user?.email}) does not have authorization to view multi-user system telemetry.

Open Demo Return to Tasks
); } const toggleRole = (id: string) => { setUsers((prev) => prev.map((u) => (u.id === id ? { ...u, role: u.role === "ADMIN" ? "USER" : "ADMIN" } : u)) ); }; const toggleStatus = (id: string) => { setUsers((prev) => prev.map((u) => (u.id === id ? { ...u, active: !u.active } : u)) ); }; const deleteUser = (id: string) => { if (confirm("Are you sure you want to delete this user and all their tasks?")) { setUsers((prev) => prev.filter((u) => u.id !== id)); } }; const filteredUsers = users.filter( (u) => u.name.toLowerCase().includes(search.toLowerCase()) || u.email.toLowerCase().includes(search.toLowerCase()) ); return (
{/* Top Navbar */}
👑

CheckFlow Admin Console

Multi-user platform & self-hosted instance management

← Back to App (Demo) 🚀 Open Main Dashboard
{/* Stats Cards */}
Total Users
{users.length}
● 100% active instances
Total Projects / Lists
{totalLists}
Across all users
Total Tasks & Notes
{totalTasks}
Recursive subtasks included
CalDAV / DAVx⁵ Status
Active
● Basic Auth Bypass Verified
{/* User Management Section */}

Registered Users & Privacy Isolation

setSearch(e.target.value)} style={{ maxWidth: 300 }} />
{/* Users Table */}
{filteredUsers.map((u) => ( ))}
User Role Joined Date Tasks Status Actions
{u.name}
{u.email}
{u.role} {new Date(u.createdAt).toLocaleDateString()} {u.taskCount} tasks {u.active ? "● Active" : "○ Inactive"}
); }