mirror of
https://github.com/andrey271192/Domain_web.git
synced 2026-09-20 14:41:58 +00:00
Add background DNS/SSL monitor checks, registration API, smoother SSE with stage labels, improved CDN/WAF detection, light-theme UI polish, and README roadmap updates. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import bcrypt from "bcryptjs";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
const bodySchema = z.object({
|
|
email: z.string().email().max(255),
|
|
password: z.string().min(8).max(128),
|
|
name: z.string().max(120).optional(),
|
|
});
|
|
|
|
export async function POST(req: NextRequest) {
|
|
let body: z.infer<typeof bodySchema>;
|
|
try {
|
|
body = bodySchema.parse(await req.json());
|
|
} catch {
|
|
return NextResponse.json({ error: "Invalid request" }, { status: 400 });
|
|
}
|
|
|
|
const email = body.email.toLowerCase();
|
|
const existing = await prisma.user.findUnique({ where: { email } });
|
|
if (existing) {
|
|
return NextResponse.json({ error: "Email already registered" }, { status: 409 });
|
|
}
|
|
|
|
const seedEmail = process.env.SEED_ADMIN_EMAIL?.toLowerCase();
|
|
const role =
|
|
seedEmail && email === seedEmail ? ("ADMIN" as const) : ("USER" as const);
|
|
|
|
const passwordHash = await bcrypt.hash(body.password, 12);
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
email,
|
|
name: body.name,
|
|
passwordHash,
|
|
role,
|
|
},
|
|
select: { id: true, email: true, role: true },
|
|
});
|
|
|
|
return NextResponse.json({ user }, { status: 201 });
|
|
}
|