Add admin foundation + Users resource (Filament replacement, slice 1)

Plain App Router admin (aligned to habbo-next, no Refine):
- rank surfaced on the NextAuth session; staff guard isStaff() [pure,
  unit-tested] + requireStaff() reading min_staff_rank, gating /admin.
- /admin dashboard (counts), /admin/users (paginated + search),
  /admin/users/[id] detail.
- src/actions/admin-users.ts: staff-gated server actions wiring the user editor
  to the existing services — giveCurrency (RCON or DB fallback), setMotto/setRank
  (DB + RCON), alertUser, disconnectUser.

Verified: tsc exit 0, vitest 45/45, next build exit 0 (/admin routes).
This commit is contained in:
Simo committed 2026-06-27 16:51:47 +02:00
1 parent d9a8ce532f
commit 9f81096f05
10 files changed
+334 -3

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
import Link from "next/link";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
const PER_PAGE = 25;
export default async function AdminUsers({
searchParams,
}: {
searchParams: Promise<{ q?: string; page?: string }>;
}) {
const sp = await searchParams;
const q = (sp.q ?? "").trim();
const page = Math.max(1, Number(sp.page ?? "1") || 1);
const where = q ? { username: { contains: q } } : {};
const [users, total] = await Promise.all([
prisma.user.findMany({
where,
select: { id: true, username: true, rank: true, credits: true, online: true },
orderBy: { id: "desc" },
skip: (page - 1) * PER_PAGE,
take: PER_PAGE,
}),
prisma.user.count({ where }),
]);
const pages = Math.max(1, Math.ceil(total / PER_PAGE));
return (
<main>
<h1>Users</h1>
<form style={{ display: "flex", gap: "0.5rem", marginBottom: "1rem" }}>
<input name="q" defaultValue={q} placeholder="Search username" />
<button type="submit">Search</button>
</form>
<table style={{ width: "100%", borderCollapse: "collapse" }}>
<thead>
<tr style={{ textAlign: "left", color: "var(--muted)" }}>
<th>ID</th>
<th>Username</th>
<th>Rank</th>
<th>Credits</th>
<th>Online</th>
</tr>
</thead>
<tbody>
{users.map((u) => (
<tr key={u.id} style={{ borderTop: "1px solid var(--border)" }}>
<td>{u.id}</td>
<td>
<Link href={`/admin/users/${u.id}`}>{u.username}</Link>
</td>
<td>{u.rank}</td>
<td>{u.credits}</td>
<td>{u.online === "1" ? "●" : "○"}</td>
</tr>
))}
</tbody>
</table>
<p className="muted">
Page {page} / {pages} · {total} users
{page < pages ? (
<>
{" · "}
<Link href={`/admin/users?q=${encodeURIComponent(q)}&page=${page + 1}`}>Next →</Link>
</>
) : null}
</p>
</main>
);
}