diff --git a/api/admin/users.ts b/api/admin/users.ts index 47583d5..98c448d 100644 --- a/api/admin/users.ts +++ b/api/admin/users.ts @@ -105,7 +105,20 @@ export default async function handler(req: NextRequest) { }); } - const body = await req.json(); + // Parse request body + let body: { isActive?: boolean; roles?: string[] }; + try { + const bodyText = await req.text(); + body = JSON.parse(bodyText); + } catch (parseError) { + return new NextResponse(JSON.stringify({ + error: 'Invalid JSON in request body' + }), { + status: 400, + headers: { 'Content-Type': 'application/json' }, + }); + } + const { isActive, roles } = body; // Update user status diff --git a/api/auth/login.ts b/api/auth/login.ts index 69f0e2a..b97d823 100644 --- a/api/auth/login.ts +++ b/api/auth/login.ts @@ -24,7 +24,20 @@ export default async function handler(req: NextRequest) { const client = await pool.connect(); try { - const body: LoginRequest = await req.json(); + // Parse request body + let body: LoginRequest; + try { + const bodyText = await req.text(); + body = JSON.parse(bodyText); + } catch (parseError) { + return new NextResponse(JSON.stringify({ + error: 'Invalid JSON in request body' + }), { + status: 400, + headers: { 'Content-Type': 'application/json' }, + }); + } + const { username, password } = body; // Validate input diff --git a/api/auth/register.ts b/api/auth/register.ts index 5f49fe7..1c2bc30 100644 --- a/api/auth/register.ts +++ b/api/auth/register.ts @@ -27,7 +27,20 @@ export default async function handler(req: NextRequest) { const client = await pool.connect(); try { - const body: RegisterRequest = await req.json(); + // Parse request body + let body: RegisterRequest; + try { + const bodyText = await req.text(); + body = JSON.parse(bodyText); + } catch (parseError) { + return new NextResponse(JSON.stringify({ + error: 'Invalid JSON in request body' + }), { + status: 400, + headers: { 'Content-Type': 'application/json' }, + }); + } + const { username, email, password, firstName, lastName } = body; // Validate input