import React, { useState } from 'react'; import './LoginForm.css'; function LoginForm({ onLogin }) { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); setError(''); setLoading(true); try { const response = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, credentials: 'include', // Important for sessions body: JSON.stringify({ username, password }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Inicio de sesi贸n fallido'); } // Success - notify parent component onLogin(data.user); } catch (error) { console.error('Login error:', error); setError(error.message || 'Usuario o contrase帽a inv谩lidos'); } finally { setLoading(false); } }; return (

馃攼 Acceso Administraci贸n

Introduce tus credenciales para acceder al panel de administraci贸n

{error && (
{error}
)}
setUsername(e.target.value)} placeholder="Introduce usuario" required autoFocus disabled={loading} />
setPassword(e.target.value)} placeholder="Introduce contrase帽a" required disabled={loading} />

Credenciales por defecto: admin / admin123

鈿狅笍 隆Cambia la contrase帽a por defecto tras el primer inicio de sesi贸n!

); } export default LoginForm;