import { type NextRequest } from 'next/server'; import { requireAdminApi } from '@/lib/auth/admin-guard'; import { parsePageParam, parsePerPageParam } from '@/lib/admin/validators'; import { getUsersList } from '@/lib/admin/list'; import { jsonNoStore } from '@/lib/admin/response'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; export async function GET(req: NextRequest) { const auth = await requireAdminApi(); if (!auth.ok) return auth.response; const url = new URL(req.url); const page = parsePageParam(url.searchParams.get('page'), 1); const perPage = parsePerPageParam(url.searchParams.get('perPage'), 25, 100); const search = url.searchParams.get('search') ?? ''; try { const { users, total } = await getUsersList({ page, perPage, search }); return jsonNoStore({ users, total, page, perPage }); } catch (e) { console.error('admin users list failed', e); return jsonNoStore({ error: 'internal error' }, { status: 500 }); } }