import { motion } from "framer-motion"; import { Lock, Unlock, Shield, WifiOff, RefreshCw } from "lucide-react"; import { useState, useCallback } from "react"; import { login, setSessionToken } from "../../shared/api/client.js"; import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input, } from "../../shared/ui"; interface AuthOverlayProps { onAuthenticated: () => void; isPublic: boolean; configError?: string | null; onRetryConfig?: () => void; } export function AuthOverlay({ onAuthenticated, isPublic, configError, onRetryConfig, }: AuthOverlayProps) { const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [isNetworkError, setIsNetworkError] = useState(false); const handleSubmit = async (e: { preventDefault: () => void }) => { e.preventDefault(); setLoading(true); setError(null); setIsNetworkError(false); try { const result = await login(password); // Store session token (new auth method) if (result.token) { setSessionToken(result.token); } // Clean up legacy stored password from localStorage if it was there // from a previous session (before JWT migration) localStorage.removeItem("admin-password"); onAuthenticated(); } catch (err) { const isNetwork = err instanceof TypeError && (err.message === "Failed to fetch" || err.message.includes("NetworkError") || err.message.includes("network")); setIsNetworkError(isNetwork); setError( isNetwork ? "Cannot reach server — check your connection or try again." : "Invalid password", ); } finally { setLoading(false); } }; // ── Retry config fetch (initial loading state) ────────────────────────────── const [retryCount, setRetryCount] = useState(0); const handleRetry = useCallback(() => { setRetryCount((r) => r + 1); }, []); return (
{isPublic ? ( ) : ( )}
{isPublic ? "Admin Authentication" : "Admin Access Required"} {isPublic ? "Enter the admin password to manage settings and perform administrative actions." : "Enter the admin password to access the dashboard."}
{configError && (

{configError}

{onRetryConfig && ( )}
)}
setPassword(e.target.value)} autoFocus /> {error && (
{isNetworkError ? ( ) : ( )} {error}
)}
{isPublic && (

The dashboard is in public mode — most data is visible without authentication. Admin password is only needed for management actions.

)}
); }