Files
Shifted/app/api/auth/signup-customer/route.ts
2026-02-10 01:14:19 +00:00

46 lines
1.1 KiB
TypeScript

import { NextResponse } from "next/server";
import bcrypt from "bcryptjs";
import { prisma } from "../../../../lib/prisma";
export async function POST(req: Request) {
try {
const body = await req.json();
const name = body.name as string;
const email = body.email as string;
const password = body.password as string;
if (!name || !email || !password) {
return NextResponse.json(
{ error: "name, email, and password are required." },
{ status: 400 }
);
}
const existing = await prisma.user.findUnique({
where: { email: email.toLowerCase() },
});
if (existing) {
return NextResponse.json({ error: "Email already in use." }, { status: 409 });
}
const passwordHash = await bcrypt.hash(password, 10);
await prisma.user.create({
data: {
name,
email: email.toLowerCase(),
passwordHash,
role: "CUSTOMER",
},
});
return NextResponse.json({ ok: true });
} catch (err: any) {
return NextResponse.json(
{ error: err?.message || "Failed to sign up." },
{ status: 500 }
);
}
}