"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; export default function AuthPage() { const router = useRouter(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [checking, setChecking] = useState(true); useEffect(() => { async function checkAuth() { try { const res = await fetch("/api/auth/check"); if (res.ok) { const callbackUrl = new URLSearchParams(window.location.search).get("callbackUrl") ?? "/"; router.push(callbackUrl); } } finally { setChecking(false); } } checkAuth(); }, [router]); async function handleLogin(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(""); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); if (!res.ok) { setError("Invalid username or password."); setLoading(false); return; } const callbackUrl = new URLSearchParams(window.location.search).get("callbackUrl") ?? "/"; router.push(callbackUrl); } catch { setError("Something went wrong. Try again."); setLoading(false); } } if (checking) return null; return (
{/* Header */}

dell-xps-nixos-serv

Login

Enter system credentials

{/* Username */}
setUsername(e.target.value)} required autoComplete="username" className="w-full px-3.5 py-2.5 border border-gray-200 rounded-xl text-sm text-gray-900 bg-gray-50 outline-none focus:border-blue-300 focus:ring-2 focus:ring-blue-50 transition-colors" />
{/* Password */}
setPassword(e.target.value)} required autoComplete="current-password" className="w-full px-3.5 py-2.5 border border-gray-200 rounded-xl text-sm text-gray-900 bg-gray-50 outline-none focus:border-blue-300 focus:ring-2 focus:ring-blue-50 transition-colors" />
{/* Error */} {error &&

{error}

} {/* Submit */}
); }