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 userList = getUsers(); return new Response(JSON.stringify(userList)); } 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 }); }