- ST-001: Next.js 16 + React 19 + TypeScript strict + Tailwind + shadcn/ui + all deps - ST-002: Prisma v7 setup with better-sqlite3 adapter (local) and pg adapter (cloud) - ST-003: Full schema migration (users, pbis, stories, sprints, tasks, todos, api_tokens) - ST-004: Seed with 9 PBIs, ~40 stories, demo user (demo/demo1234), lars user - ST-005: Zod-validated env vars, .env.example, lib/session, lib/auth, lib/api-auth Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
902 B
TypeScript
34 lines
902 B
TypeScript
import bcrypt from 'bcryptjs'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
export async function registerUser(username: string, password: string) {
|
|
const existing = await prisma.user.findUnique({ where: { username } })
|
|
if (existing) {
|
|
return { error: 'Gebruikersnaam is al in gebruik' }
|
|
}
|
|
|
|
if (password.length < 8) {
|
|
return { error: 'Wachtwoord moet minimaal 8 tekens bevatten' }
|
|
}
|
|
|
|
const password_hash = await bcrypt.hash(password, 12)
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
username,
|
|
password_hash,
|
|
roles: { create: [{ role: 'DEVELOPER' }] },
|
|
},
|
|
})
|
|
|
|
return { user }
|
|
}
|
|
|
|
export async function verifyUser(username: string, password: string) {
|
|
const user = await prisma.user.findUnique({ where: { username } })
|
|
if (!user) return null
|
|
|
|
const valid = await bcrypt.compare(password, user.password_hash)
|
|
if (!valid) return null
|
|
|
|
return user
|
|
}
|