import { useState, type FormEvent, type ReactNode } from 'react' import { Activity, AlertCircle, LoaderCircle, ShieldCheck } from 'lucide-react' import { useApi } from './ApiProvider' import './auth-gate.css' export function AuthGate({ children }: { children: ReactNode }) { const { authState, authError } = useApi() if (authState === 'checking') { return
Connecting to MentorAMP…
} if (authState === 'authenticated') return <>{children} return } function AuthPanel({ unavailable, error }: { unavailable: boolean; error: string | null }) { const { baseUrl, request, signIn } = useApi() const [mode, setMode] = useState<'sign-in' | 'bootstrap'>('sign-in') const [email, setEmail] = useState('') const [fullName, setFullName] = useState('') const [password, setPassword] = useState('') const [message, setMessage] = useState('') const [busy, setBusy] = useState(false) const submit = async (event: FormEvent) => { event.preventDefault() setBusy(true) setMessage('') try { if (mode === 'bootstrap') { await request('/v1/auth/bootstrap', { method: 'POST', body: JSON.stringify({ email, full_name: fullName, password }), }) } await signIn(email, password) } catch (caught) { setMessage(caught instanceof Error ? caught.message : 'Authentication failed.') } finally { setBusy(false) } } return
MentorAMP
SECURE ACTUARIAL WORKSPACE

{mode === 'bootstrap' ? 'Set up the first administrator' : 'Sign in to MentorAMP'}

{mode === 'bootstrap' ? 'Create the initial administrator for this new database. This is available only until the first user is created.' : 'Use your backend account to access live models, inputs, projection runs, and reports.'}

{(unavailable || message) &&
{message || error || `Could not reach the backend at ${baseUrl}.`}
}
{mode === 'bootstrap' && }
{!unavailable && } API: {baseUrl}
}