feat: username/ww login, tijdzone fix, Vannacht → Eergisternacht"
Some checks failed
Build & Deploy / build (push) Failing after 1m11s
Some checks failed
Build & Deploy / build (push) Failing after 1m11s
This commit is contained in:
34
src/app/api/auth/register/route.ts
Normal file
34
src/app/api/auth/register/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { username, password } = await req.json();
|
||||
|
||||
if (!username || !password) {
|
||||
return NextResponse.json({ error: "Gebruikersnaam en wachtwoord zijn verplicht." }, { status: 400 });
|
||||
}
|
||||
if (username.length < 3) {
|
||||
return NextResponse.json({ error: "Gebruikersnaam moet minstens 3 tekens zijn." }, { status: 400 });
|
||||
}
|
||||
if (password.length < 6) {
|
||||
return NextResponse.json({ error: "Wachtwoord moet minstens 6 tekens zijn." }, { status: 400 });
|
||||
}
|
||||
|
||||
const existing = await prisma.user.findUnique({ where: { username } });
|
||||
if (existing) {
|
||||
return NextResponse.json({ error: "Deze gebruikersnaam is al in gebruik." }, { status: 409 });
|
||||
}
|
||||
|
||||
const hashed = await bcrypt.hash(password, 12);
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
username,
|
||||
name: username,
|
||||
password: hashed,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
Reference in New Issue
Block a user