This commit is contained in:
2026-06-11 13:25:26 +03:00
parent b931ee64d4
commit 60b48ca5e8
60 changed files with 12302 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
'use server'
import { login } from '@/lib/auth'
import prisma from '@/lib/prisma'
import bcrypt from 'bcryptjs'
import { redirect } from 'next/navigation'
export async function authenticate(prevState: any, formData: FormData) {
const username = formData.get('username') as string
const password = formData.get('password') as string
if (!username || !password) {
return { error: 'Lütfen tüm alanları doldurun.' }
}
try {
// Check user in database
const user = await prisma.users.findUnique({
where: { username }
})
if (!user) {
return { error: 'Kullanıcı adı veya şifre hatalı.' }
}
const passwordsMatch = await bcrypt.compare(password, user.password_hash)
if (!passwordsMatch) {
return { error: 'Kullanıcı adı veya şifre hatalı.' }
}
await login(username)
} catch (error) {
console.error('Login error:', error)
return { error: 'Bir hata oluştu, lütfen tekrar deneyin.' }
}
// Redirect to admin dashboard after successful login
redirect('/admin')
}