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 } } : {}; // .catch(...) keeps the precise selected-row type while falling back to an // empty page when the DB is unavailable (instead of a 500). const users = await 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, }) .catch(() => []); const total = await prisma.user.count({ where }).catch(() => 0); const pages = Math.max(1, Math.ceil(total / PER_PAGE)); return (

Users

{users.map((u) => ( ))}
ID Username Rank Credits Online
{u.id} {u.username} {u.rank} {u.credits} {u.online === "1" ? "●" : "○"}

Page {page} / {pages} · {total} users {page < pages ? ( <> {" · "} Next → ) : null}

); }