Files
biblical-guide.com/app/api/auth/register/route.ts
andupetcu 3b375c869b Add complete Biblical Guide web application with Material UI
Implemented comprehensive Romanian Biblical Guide web app:
- Next.js 15 with App Router and TypeScript
- Material UI 7.3.2 for modern, responsive design
- PostgreSQL database with Prisma ORM
- Complete Bible reader with book/chapter navigation
- AI-powered biblical chat with Romanian responses
- Prayer wall for community prayer requests
- Advanced Bible search with filters and highlighting
- Sample Bible data imported from API.Bible
- All API endpoints created and working
- Professional Material UI components throughout
- Responsive layout with navigation and theme

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-20 14:10:28 +03:00

50 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server'
import { createUser, generateToken } from '@/lib/auth'
import { prisma } from '@/lib/db'
import { userRegistrationSchema } from '@/lib/validation'
import { z } from 'zod'
export async function POST(request: Request) {
try {
const body = await request.json()
// Validate input
const result = userRegistrationSchema.safeParse(body)
if (!result.success) {
const errors = result.error.errors.map(err => err.message).join(', ')
return NextResponse.json({ error: errors }, { status: 400 })
}
const { email, password, name } = result.data
// Check if user exists
const existing = await prisma.user.findUnique({ where: { email } })
if (existing) {
return NextResponse.json({ error: 'Utilizatorul există deja' }, { status: 409 })
}
// Create user
const user = await createUser(email, password, name)
const token = generateToken(user.id)
// Create session
await prisma.session.create({
data: {
userId: user.id,
token,
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
}
})
return NextResponse.json({
user: { id: user.id, email: user.email, name: user.name },
token
})
} catch (error) {
console.error('Registration error:', error)
if (error instanceof z.ZodError) {
return NextResponse.json({ error: 'Date de intrare invalide' }, { status: 400 })
}
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
}
}