import { useState, useEffect, useRef } from 'react'; import './AuthScreen.css'; function AuthScreen({ onAuth, darkMode, setDarkMode }) { const [stage, setStage] = useState('splash'); // 'splash' | 'enter' const [username, setUsername] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [transitioning, setTransitioning] = useState(false); const inputRef = useRef(null); // Focus input when entering name stage useEffect(() => { if (stage === 'enter' && inputRef.current) { setTimeout(() => inputRef.current.focus(), 600); } }, [stage]); const handleEnterClick = () => { setTransitioning(true); setTimeout(() => { setStage('enter'); setTransitioning(false); }, 500); }; const handleSubmit = async (e) => { e.preventDefault(); if (!username.trim()) return; setError(''); setLoading(true); try { const res = await fetch('/api/v1/auth/enter', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: username.trim() }), }); const data = await res.json(); if (!res.ok) { const msg = Array.isArray(data.detail) ? data.detail[0]?.msg ?? 'Invalid input' : data.detail ?? 'Something went wrong'; setError(msg); return; } localStorage.setItem('soma_token', data.access_token); localStorage.setItem('soma_username', data.username); onAuth(data.username); } catch { setError('Could not reach the server. Is it running?'); } finally { setLoading(false); } }; return (
{/* Dark Mode Toggle */} {/* Animated background */}
{/* Floating particles */}
{Array.from({ length: 20 }).map((_, i) => (
))}
{/* ══════ STAGE 1: Splash ══════ */} {stage === 'splash' && (
{/* Neural orb */}

SOMA

Cognitive Architecture for AI

A brain-inspired system that builds memory as you talk. Every conversation shapes a living neural mesh — unique to you.

{/* Features row */}
Sensory Memory
Knowledge Graph
Neural Dreaming
Press Enter or click to begin
)} {/* ══════ STAGE 2: Name Input ══════ */} {stage === 'enter' && (
{/* Small orb */}

Who are you?

Enter your name to initialize your neural space. New here? We'll create your brain automatically.

setUsername(e.target.value)} placeholder="Type your name..." autoComplete="username" required />
{error &&

{error}

}
)} {/* Footer */}
); } export default AuthScreen;