import Link from "next/link"; import { notFound } from "next/navigation"; import { updateUser } from "@/actions/admin-user-edit"; import { requireStaff } from "@/lib/admin/guard"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; // users_currency.type values for the non-credits currencies (see send-currency.ts). const DUCKETS_TYPE = 0; const DIAMONDS_TYPE = 5; export default async function AdminUserEdit({ params, }: { params: Promise<{ id: string }>; }) { // Gate the page with the SAME helper the action re-checks. await requireStaff(); const { id } = await params; const userId = Number(id); if (!Number.isInteger(userId) || userId <= 0) notFound(); let user: { id: number; username: string; mail: string | null; motto: string; look: string; rank: number; credits: number; pixels: number; points: number; } | null = null; let duckets = 0; let diamonds = 0; try { user = await prisma.user.findUnique({ where: { id: userId }, select: { id: true, username: true, mail: true, motto: true, look: true, rank: true, credits: true, pixels: true, points: true, }, }); if (user) { const currencies = await prisma.usersCurrency.findMany({ where: { userId, type: { in: [DUCKETS_TYPE, DIAMONDS_TYPE] } }, select: { type: true, amount: true }, }); for (const c of currencies) { if (c.type === DUCKETS_TYPE) duckets = c.amount; else if (c.type === DIAMONDS_TYPE) diamonds = c.amount; } } } catch { return ( ← Users Edit user Could not load this user right now. Try again shortly. ); } if (!user) notFound(); return ( ← {user.username} Edit {user.username} ID {user.id} Email Rank Motto Look Credits Pixels Points Duckets Diamonds Currency fields set the exact balance, not a delta. Passwords are not editable here. Save changes Cancel ); }
← Users
Could not load this user right now. Try again shortly.
← {user.username}
ID {user.id}
Currency fields set the exact balance, not a delta. Passwords are not editable here.