mythic-bastionland/app/api/signup/route.ts
2025-10-10 19:44:33 +11:00

19 lines
770 B
TypeScript

import { NextResponse } from "next/server"
import prisma from "@/lib/prisma"
import { hash } from "bcryptjs"
export async function POST(req: Request) {
const body = await req.json().catch(() => null) as { email?: string; password?: string; name?: string } | null
if (!body?.email || !body?.password) return NextResponse.json({ error: "Missing fields" }, { status: 400 })
const existing = await prisma.user.findUnique({ where: { email: body.email } })
if (existing) return NextResponse.json({ error: "Email in use" }, { status: 409 })
const password = await hash(body.password, 10)
const user = await prisma.user.create({ data: { email: body.email, name: body.name ?? null, password } })
return NextResponse.json({ id: user.id, email: user.email })
}