From 75b0b2e67753656ba1a6c266c235fbf294495501 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sat, 22 Feb 2025 08:09:01 -0800 Subject: [PATCH] Make user id optional. --- src/app/api/users/route.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/api/users/route.ts b/src/app/api/users/route.ts index f6b32fe7..c5896f89 100644 --- a/src/app/api/users/route.ts +++ b/src/app/api/users/route.ts @@ -8,6 +8,7 @@ import { createUser, getUserByUsername } from '@/queries'; export async function POST(request: Request) { const schema = z.object({ + id: z.string().uuid().optional(), username: z.string().max(255), password: z.string(), role: z.string().regex(/admin|user|view-only/i), @@ -23,7 +24,7 @@ export async function POST(request: Request) { return unauthorized(); } - const { username, password, role } = body; + const { id, username, password, role } = body; const existingUser = await getUserByUsername(username, { showDeleted: true }); @@ -32,7 +33,7 @@ export async function POST(request: Request) { } const user = await createUser({ - id: uuid(), + id: id || uuid(), username, password: hashPassword(password), role: role ?? ROLES.user,