import Link from "next/link"; import { changeUserRoleAction, createUserAction, deleteUserAction, } from "@/app/actions/users"; import { Flash } from "@/components/flash"; import { ResetUserPassword } from "@/components/reset-user-password"; import { requireAdminUser } from "@/lib/auth"; import { db, initDatabase } from "@/lib/db"; import { formatDate, queryMessage } from "@/lib/format"; import type { UserRole } from "@/lib/types"; export const runtime = "nodejs"; type UserRow = { id: number; name: string; role: UserRole; created_at: string; }; export default async function AdminUsersPage({ searchParams, }: { searchParams: Promise>; }) { const currentUser = await requireAdminUser(); initDatabase(); const params = await searchParams; const users = db .prepare( "SELECT id, name, role, created_at FROM users WHERE active = 1 ORDER BY name COLLATE NOCASE", ) .all() as UserRow[]; const adminCount = users.filter((u) => u.role === "admin").length; const currentAdminKeyCount = db .prepare("SELECT COUNT(*) AS count FROM webauthn_credentials WHERE user_id = ?") .get(currentUser.id) as { count: number }; return ( <>
Übersicht / Benutzer

Administration

Benutzerverwaltung

{users.length} Konten · {adminCount} Administrator(en)

Team

Konten

{users.map((row) => { const lastAdmin = row.role === "admin" && adminCount <= 1; const isSelf = row.id === currentUser.id; return ( ); })}
Name Rolle Angelegt
{row.name}{isSelf && Du}
{formatDate(row.created_at.slice(0, 10))} {!isSelf && (
0} /> {!lastAdmin && (
)}
)}

Neu

Benutzer anlegen

); }