// Sign-in, sign-up and account security. // // Accounts: a username, a passkey and/or a password, and an optional email // that only counts once confirmed (it's for password resets and signing in). // Cloudflare Turnstile is shown only while the server enforces it // (/api/config → turnstileSiteKey); without it everything still works. // Every email feature (the field, email sign-in, forgot password) is shown // only while the server can send email (/api/config → emailEnabled). // ── Cloudflare Turnstile widget ─────────────────────────────── let turnstileScript; function loadTurnstile() { turnstileScript = turnstileScript || new Promise((resolve, reject) => { const s = document.createElement('script'); s.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'; s.async = true; s.onload = resolve; s.onerror = () => { turnstileScript = null; reject(new Error('Turnstile failed to load')); }; document.head.appendChild(s); }); return turnstileScript; } // Tokens are single-use: bump `resetSignal` after every submit. function TurnstileWidget({ siteKey, onToken, resetSignal }) { const el = React.useRef(null); const widgetId = React.useRef(null); React.useEffect(() => { if (!siteKey) return; let cancelled = false; loadTurnstile().then(() => { if (cancelled || !el.current) return; widgetId.current = window.turnstile.render(el.current, { sitekey: siteKey, theme: 'dark', callback: (token) => onToken(token), 'expired-callback': () => onToken(null), 'error-callback': () => onToken(null), }); }).catch(() => onToken(null)); return () => { cancelled = true; if (widgetId.current != null && window.turnstile) window.turnstile.remove(widgetId.current); widgetId.current = null; }; }, [siteKey]); React.useEffect(() => { if (resetSignal && widgetId.current != null && window.turnstile) { window.turnstile.reset(widgetId.current); onToken(null); } }, [resetSignal]); if (!siteKey) return null; return
; } // ── Small pieces ────────────────────────────────────────────── const fullWidth = { width: '100%', justifyContent: 'center' }; function ErrorNote({ text }) { if (!text) return null; return (