'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; export default function LoginPage() { const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const router = useRouter(); async function handleLogin() { if (!password || loading) return; setLoading(true); setError(''); try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ password }), }); if (!res.ok) throw new Error('Invalid password'); router.push('/'); router.refresh(); } catch { setError('Invalid password'); setLoading(false); } } function handleKeyDown(e: React.KeyboardEvent) { if (e.key === 'Enter') handleLogin(); } return (
Aaron AI
personal knowledge assistant
setPassword(e.target.value)} onKeyDown={handleKeyDown} placeholder="Password" autoFocus autoComplete="current-password" style={{ width: '100%', background: '#faf9f6', border: `1px solid ${error ? '#a32d2d' : '#ccc9c0'}`, borderRadius: '10px', padding: '12px 16px', fontSize: '16px', color: '#1a1a18', outline: 'none', marginBottom: error ? '6px' : '16px', display: 'block', boxSizing: 'border-box', }} /> {error && (
{error}
)}
); }