import { useState, type FormEvent } from "react"; import { useNavigate } from "react-router-dom"; import { useAuth } from "../context/AuthContext"; export default function LoginPage() { const { login, isAuthenticated } = useAuth(); const navigate = useNavigate(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); // If already logged in, redirect immediately if (isAuthenticated) { navigate("/dashboard", { replace: true }); return null; } async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(null); setLoading(true); try { await login(username, password); navigate("/dashboard", { replace: true }); } catch { setError("Invalid username or password"); } finally { setLoading(false); } } return (
{/* Logo */}
Aegis

Aegis

MITRE ATT&CK Coverage Platform

{/* Form */}
setUsername(e.target.value)} className="w-full rounded-lg border border-gray-700 bg-gray-900 px-3 py-2 text-sm text-white placeholder-gray-500 outline-none focus:border-cyan-500 focus:ring-1 focus:ring-cyan-500" placeholder="admin" />
setPassword(e.target.value)} className="w-full rounded-lg border border-gray-700 bg-gray-900 px-3 py-2 text-sm text-white placeholder-gray-500 outline-none focus:border-cyan-500 focus:ring-1 focus:ring-cyan-500" placeholder="••••••••" />
{error && (

{error}

)}
); }