34 lines
924 B
TypeScript
Raw Normal View History

2025-05-17 14:51:16 +02:00
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
interface Body {
username: string;
name: string;
email: string;
password: string;
}
export async function POST(request: NextRequest) {
try {
const body: Body = await request.json();
if (!body.username || !body.name || !body.email || !body.password) {
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
}
const user = await prisma.user.create({
data: {
username: body.username,
name: body.name,
email: body.email,
password: body.password,
},
});
return NextResponse.json({ user }, { status: 201 });
} catch (error: any) {
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}