"use client"; import { Loader2, Shield } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { login } from "@/lib/api"; export default function LoginPage() { const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [checking, setChecking] = useState(true); const router = useRouter(); useEffect(() => { const stored = localStorage.getItem("admin-password"); if (stored) { login(stored) .then((ok) => { if (ok) router.replace("/dashboard"); else setChecking(false); }) .catch(() => setChecking(false)); } else { setChecking(false); } }, [router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setLoading(true); try { const ok = await login(password); if (ok) { localStorage.setItem("admin-password", password); router.push("/dashboard"); } else { setError("Invalid password"); } } catch { setError("Connection failed. Is the backend running?"); } finally { setLoading(false); } }; if (checking) { return (
); } return (

Bete

Discord Moderation Dashboard

setPassword(e.target.value)} placeholder="Enter admin password" className="flex h-9 w-full rounded-lg border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-50" disabled={loading} />
{error &&

{error}

}
); }