/** * Login View - Web mode authentication * * Prompts user to enter the API key shown in server console. * On successful login, sets an HTTP-only session cookie. */ import { useState } from 'react'; import { useNavigate } from '@tanstack/react-router'; import { login } from '@/lib/http-api-client'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { KeyRound, AlertCircle, Loader2 } from 'lucide-react'; import { useAuthStore } from '@/store/auth-store'; import { useSetupStore } from '@/store/setup-store'; export function LoginView() { const navigate = useNavigate(); const setAuthState = useAuthStore((s) => s.setAuthState); const setupComplete = useSetupStore((s) => s.setupComplete); const [apiKey, setApiKey] = useState(''); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setIsLoading(true); try { const result = await login(apiKey.trim()); if (result.success) { // Mark as authenticated for this session (cookie-based auth) setAuthState({ isAuthenticated: true, authChecked: true }); // After auth, determine if setup is needed or go to app navigate({ to: setupComplete ? '/' : '/setup' }); } else { setError(result.error || 'Invalid API key'); } } catch (err) { setError('Failed to connect to server'); } finally { setIsLoading(false); } }; return (
{/* Header */}

Authentication Required

Enter the API key shown in the server console to continue.

{/* Login Form */}
setApiKey(e.target.value)} disabled={isLoading} autoFocus className="font-mono" data-testid="login-api-key-input" />
{error && (
{error}
)}
{/* Help Text */}

Where to find the API key:

  1. Look at the server terminal/console output
  2. Find the box labeled "API Key for Web Mode Authentication"
  3. Copy the UUID displayed there
); }