mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 16:07:10 +00:00
Create User API Route
This commit is contained in:
parent
735deb9efe
commit
e9fe5bb22a
34
app/api/user/create/route.ts
Normal file
34
app/api/user/create/route.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
||||
5
app/prisma.ts
Normal file
5
app/prisma.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { PrismaClient } from "@/prisma/generated/prisma";
|
||||
|
||||
let prisma = new PrismaClient();
|
||||
|
||||
export default prisma;
|
||||
Loading…
x
Reference in New Issue
Block a user