Skip to content

Commit

Permalink
Make user id optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Feb 22, 2025
1 parent a7ded80 commit 75b0b2e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/api/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 });

Expand All @@ -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,
Expand Down

0 comments on commit 75b0b2e

Please sign in to comment.