Make user id optional.
This commit is contained in:
@@ -8,6 +8,7 @@ import { createUser, getUserByUsername } from '@/queries';
|
|||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
|
id: z.string().uuid().optional(),
|
||||||
username: z.string().max(255),
|
username: z.string().max(255),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
role: z.string().regex(/admin|user|view-only/i),
|
role: z.string().regex(/admin|user|view-only/i),
|
||||||
@@ -23,7 +24,7 @@ export async function POST(request: Request) {
|
|||||||
return unauthorized();
|
return unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { username, password, role } = body;
|
const { id, username, password, role } = body;
|
||||||
|
|
||||||
const existingUser = await getUserByUsername(username, { showDeleted: true });
|
const existingUser = await getUserByUsername(username, { showDeleted: true });
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = await createUser({
|
const user = await createUser({
|
||||||
id: uuid(),
|
id: id || uuid(),
|
||||||
username,
|
username,
|
||||||
password: hashPassword(password),
|
password: hashPassword(password),
|
||||||
role: role ?? ROLES.user,
|
role: role ?? ROLES.user,
|
||||||
|
|||||||
Reference in New Issue
Block a user