import React, { useState, useEffect, useRef } from 'react'; import { ShieldCheck, Cpu, Key, Terminal, Lock, Loader2, CheckCircle2, Zap, ShieldAlert, ArrowRight, Fingerprint, FileCheck, UserPlus } from 'lucide-react'; import { apiClient } from '../services/api.ts'; const Login: React.FC = () => { const [loading, setLoading] = useState(false); const [isRegistering, setIsRegistering] = useState(false); const [stage, setStage] = useState<'IDLE' | 'AUTHORIZING' | 'CONSENT' | 'EXCHANGING' | 'VERIFIED'>('IDLE'); const [logs, setLogs] = useState(["LQI Auth Engine v1.3.0 (Persistent DB) initializing..."]); const [error, setError] = useState(null); const [successMsg, setSuccessMsg] = useState(null); const logEndRef = useRef(null); const [params, setParams] = useState({ username: '', password: '', }); useEffect(() => { logEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [logs]); const addLog = (msg: string) => setLogs(prev => [...prev, `${new Date().toLocaleTimeString()} - ${msg}`]); const handleAuth = async (e: React.FormEvent) => { e.preventDefault(); if (loading) return; setLoading(true); setError(null); setSuccessMsg(null); addLog(`INIT: Establishing ${isRegistering ? 'Registration' : 'Login'} protocol handshake...`); try { if (isRegistering) { const { success, error: regError } = await apiClient.auth.register(params.username, params.password); if (success) { addLog("DB_WRITE: New identity node successfully written to disk."); setSuccessMsg("Registration complete. Initialize handshake to sign in."); setIsRegistering(false); } else { throw new Error(regError || "Registration handshake denied."); } } else { const { success, user, error: loginError } = await apiClient.auth.login(params.username, params.password); if (success && user) { addLog("DB_QUERY: Identity parity confirmed via cryptographic hash."); setStage('VERIFIED'); setTimeout(() => { window.dispatchEvent(new Event('auth-update')); }, 1000); } else { throw new Error(loginError || "Handshake rejected by identity node."); } } } catch (err: any) { addLog(`CRITICAL: ${err.message}`); setError(err.message); } finally { setLoading(false); } }; return (

Lumina Quantum

Identity v1.3.0

{isRegistering ? 'Register' : 'Handshake'}
Protocol

Establish a secure session fabric using persistent node storage and RSA-OAEP-4096 hashing.

Quantum Trace Stream
{logs.map((log, i) => (
{log}
))}
{stage === 'VERIFIED' ? (

Authenticated

Initializing Subspace Ledger...

) : (

{isRegistering ? 'Create Identity' : 'Identity Core'}

Secure Link
setParams({...params, username: e.target.value})} className="w-full bg-black border border-zinc-800 rounded-2xl py-4 pl-12 pr-4 text-white font-mono text-sm outline-none focus:border-blue-500 transition-all shadow-inner" placeholder="Node Identifier" required />
setParams({...params, password: e.target.value})} className="w-full bg-black border border-zinc-800 rounded-2xl py-4 pl-12 pr-4 text-white font-mono text-sm outline-none focus:border-blue-500 transition-all shadow-inner" placeholder="••••••••" required />
{error && (
{error}
)} {successMsg && (
{successMsg}
)}
)}
); }; export default Login;