refactor addUser API endpoint to return user object if successful

This commit is contained in:
2025-08-19 12:56:28 +02:00
parent ef0b981d84
commit 9d54a0fdb8
2 changed files with 11 additions and 10 deletions

View File

@@ -24,7 +24,11 @@ export async function POST({ request, locals }) {
return json({ error: 'Missing input' }, { status: 400 });
}
const rowCount = addUser(userName, userPassword);
const rowInfo = addUser(userName, userPassword);
return new Response(null, { status: rowCount == 1 ? 200 : 400 });
if (rowInfo?.changes == 1) {
return json({ userId: rowInfo.lastInsertRowid, userName: userName }, { status: 201 });
} else {
return new Response(null, { status: 400 });
}
}