'use client'; import { useState, type FormEvent } from 'react'; import { useRouter } from 'next/navigation'; import { Shield } from 'lucide-react'; import { useConfig } from '@/hooks/use-config'; import { useThemeStore } from '@/stores/theme-store'; import { apiFetch, withBasePath } from '@/lib/browser-navigation'; export default function AdminLoginPage() { const router = useRouter(); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const { loginLogoLightUrl, loginLogoDarkUrl } = useConfig(); const resolvedTheme = useThemeStore((s) => s.resolvedTheme); const logoUrl = withBasePath(resolvedTheme === 'dark' ? loginLogoDarkUrl : loginLogoLightUrl); async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(''); setLoading(true); try { const res = await apiFetch('/api/admin/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }), }); const data = await res.json(); if (!res.ok) { setError(data.error || 'Login failed'); return; } router.push('/admin'); } catch { setError('Network error. Please try again.'); } finally { setLoading(false); } } return (
Enter your admin password to continue