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 (
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 */}Enter your name to initialize your neural space. New here? We'll create your brain automatically.