import { useState } from 'react'; import { useRouter } from 'next/router'; export default function Login() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const router = useRouter(); const handleLogin = async (e) => { e.preventDefault(); try { const res = await fetch('http://localhost:9002/posts/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) }); const data = await res.json(); if (res.ok) { localStorage.setItem('blog_token', data.token); router.push('/admin'); } else { alert('Credenciales incorrectas'); } } catch (err) { alert('Error de conexión'); } }; return (

Admin Login šŸ”

setUsername(e.target.value)} style={{ width: '100%', padding: '14px', border: '2px solid #e2e8f0', borderRadius: '10px', marginBottom: '20px', fontSize: '1rem', boxSizing: 'border-box', outline: 'none' }} /> setPassword(e.target.value)} style={{ width: '100%', padding: '14px', border: '2px solid #e2e8f0', borderRadius: '10px', marginBottom: '30px', fontSize: '1rem', boxSizing: 'border-box', outline: 'none' }} />
); }