Files
biblical-guide.com/app/api/auth/login/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

46 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server'
import { validateUser, generateToken } from '@/lib/auth'
import { prisma } from '@/lib/db'
export async function POST(request: Request) {
try {
const { email, password } = await request.json()
// Validation
if (!email || !password) {
return NextResponse.json({ error: 'Email și parola sunt obligatorii' }, { status: 400 })
}
// Validate user
const user = await validateUser(email, password)
if (!user) {
return NextResponse.json({ error: 'Email sau parolă incorectă' }, { status: 401 })
}
// Generate token
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)
}
})
// Update last login
await prisma.user.update({
where: { id: user.id },
data: { lastLoginAt: new Date() }
})
return NextResponse.json({
user: { id: user.id, email: user.email, name: user.name },
token
})
} catch (error) {
console.error('Login error:', error)
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
}
}