'use client' import React, { useState } from 'react' import { signIn } from 'next-auth/react' import { useRouter } from 'next/navigation' interface LoginFormProps { messages: { common: { email: string password: string } login: { emailPlaceholder: string passwordPlaceholder: string button: string loading: string error: string invalidCredentials: string } } } export default function LoginForm({ messages }: LoginFormProps) { const router = useRouter() const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError(null) try { const formData = new FormData(e.currentTarget) const email = formData.get('email') as string const password = formData.get('password') as string console.log('Giriş denemesi:', email) const result = await signIn('credentials', { email, password, redirect: false }) console.log('Giriş sonucu:', result) if (result?.error) { console.error('Giriş hatası:', result.error) setError(messages.login.invalidCredentials) return } if (!result?.ok) { console.error('Giriş başarısız:', result) setError(messages.login.error) return } console.log('Giriş başarılı, yönlendiriliyor...') router.push('/dashboard') } catch (error) { console.error('Beklenmeyen giriş hatası:', error) setError(messages.login.error) } finally { setLoading(false) } } return (
{error && (

{error}

)}
) }