user list and possibility of adding new users implemented on FE and BE

This commit is contained in:
2025-08-06 08:37:24 +02:00
parent b5ff4a72fb
commit 26b94938a9
4 changed files with 253 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { json } from '@sveltejs/kit';
import { addUser, getUsers } from '$lib/server/userService';
export function GET({ locals }) {
if (!locals.user) {
return json({ error: 'Unauthorized' }, { status: 401 });
}
const users_list = getUsers();
return new Response(JSON.stringify(users_list));
}
export async function POST({ request, locals }) {
if (!locals.user) {
return json({ error: 'Unauthorized' }, { status: 401 });
}
const data = await request.json();
const userName = data.userName;
const userPassword = data.userPassword;
const rowCount = addUser(userName, userPassword);
return new Response(null, { status: rowCount == 1 ? 200 : 400 });
}