Files
BaraBingo/app/api/auth/register/route.ts
SlavaVlad 05677924b5
Some checks failed
Deploy / build-and-deploy (push) Failing after 2m53s
V1 bingo
2026-06-14 21:29:43 +03:00

25 lines
906 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { registerUser } from "@/lib/auth";
export async function POST(req: NextRequest) {
try {
const { nickname, password } = await req.json();
if (!nickname || !password) {
return NextResponse.json({ error: "Nickname and password required" }, { status: 400 });
}
if (nickname.length < 2 || nickname.length > 20) {
return NextResponse.json({ error: "Nickname 2-20 characters" }, { status: 400 });
}
if (password.length < 4) {
return NextResponse.json({ error: "Password min 4 characters" }, { status: 400 });
}
const result = await registerUser(nickname, password);
if ("error" in result) {
return NextResponse.json(result, { status: 409 });
}
return NextResponse.json(result);
} catch {
return NextResponse.json({ error: "Registration failed" }, { status: 500 });
}
}