// 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 (
{text}
); } function Divider({ label }) { return (
{label}
); } function Hint({ children }) { return
{children}
; } function TextLink({ onClick, children }) { return {children}; } // A cancelled passkey prompt isn't an error worth shouting about. function passkeyError(err, fallback) { if (err && (err.name === 'NotAllowedError' || err.name === 'AbortError')) return 'Passkey prompt was cancelled'; return (err && err.message) || fallback; } // ── Sign-in / sign-up modal ─────────────────────────────────── function SignInModal({ onClose, onSignIn, resetToken }) { // login | register | forgot | forgot-sent | reset const [mode, setMode] = React.useState(resetToken ? 'reset' : 'login'); const [login, setLogin] = React.useState(''); const [password, setPassword] = React.useState(''); const [username, setUsername] = React.useState(''); const [email, setEmail] = React.useState(''); const [error, setError] = React.useState(''); const [busy, setBusy] = React.useState(false); const [siteKey, setSiteKey] = React.useState(null); const [emailOn, setEmailOn] = React.useState(false); const [token, setToken] = React.useState(null); const [resetSignal, setResetSignal] = React.useState(0); const passkeys = window.api.passkeysSupported(); React.useEffect(() => { window.api.getConfig().then(c => { setSiteKey(c.turnstileSiteKey || null); setEmailOn(!!c.emailEnabled); }).catch(() => {}); }, []); const switchMode = (next) => { setMode(next); setError(''); }; const needsToken = () => siteKey && !token; // Runs an action; Turnstile tokens are single-use, so always reset after. const run = async (fn, fallback) => { setError(''); setBusy(true); try { await fn(); } catch (err) { setError(passkeyError(err, fallback)); } finally { setBusy(false); setResetSignal(n => n + 1); } }; const signInWithPasskey = () => run(async () => { onSignIn(await window.api.loginWithPasskey()); }, 'Passkey sign-in failed'); const signInWithPassword = () => { if (needsToken()) return setError('Please complete the anti-bot check'); return run(async () => { onSignIn(await window.api.login({ login, password, turnstileToken: token })); }, 'Sign-in failed'); }; const profileOk = () => { if (!/^[a-zA-Z0-9_]{3,30}$/.test(username.trim())) { setError('Username: 3–30 letters, digits or _'); return false; } if (needsToken()) { setError('Please complete the anti-bot check'); return false; } return true; }; const signUpWithPasskey = () => { if (!profileOk()) return; return run(async () => { onSignIn(await window.api.registerWithPasskey({ username, email, turnstileToken: token })); }, 'Could not create the passkey'); }; const signUpWithPassword = () => { if (!profileOk()) return; if (password.length < 8) return setError('Password must be at least 8 characters'); return run(async () => { onSignIn(await window.api.register({ username, email, password, turnstileToken: token })); }, 'Registration failed'); }; const sendReset = () => { if (!login.trim()) return setError('Enter your username or email'); if (needsToken()) return setError('Please complete the anti-bot check'); return run(async () => { await window.api.forgotPassword({ login, turnstileToken: token }); setMode('forgot-sent'); }, 'Could not send reset link'); }; const setNewPassword = () => { if (password.length < 8) return setError('Password must be at least 8 characters'); return run(async () => { onSignIn(await window.api.resetPassword({ token: resetToken, password })); }, 'Reset failed — the link may be expired'); }; const titles = { login: 'Sign in to the archive', register: 'Create an account', forgot: 'Reset your password', 'forgot-sent': 'Check your email', reset: 'Set a new password', }; const subtitles = { login: 'An account lets you submit reports and join discussions.', register: passkeys ? 'No real name or email needed. A passkey signs you in with your fingerprint, face or device PIN: nothing to remember, nothing to leak.' : 'No real name or email needed.', forgot: "Enter your username or email. If the account has a confirmed email, we'll send a link there.", 'forgot-sent': "If the account has a confirmed email, a reset link is on its way. It's valid for one hour.", reset: 'Choose a new password (at least 8 characters). All other sessions on this account will be signed out.', }; const turnstile = ; return (
e.stopPropagation()} style={{ width: 400, maxWidth: 'calc(100vw - 32px)', background: 'var(--bg-1)', border: '1px solid var(--line-2)', padding: 40, margin: 'auto' }}>
OPEN UFO ARCHIVE
{titles[mode]}
{subtitles[mode]}
{mode === 'login' && ( <> {passkeys && ( <> )}
{emailOn ? 'Username or email' : 'Username'}
setLogin(e.target.value)} style={{ marginBottom: 16 }} />
Password
setPassword(e.target.value)} style={{ marginBottom: emailOn ? 8 : 18 }} /> {emailOn && (
switchMode('forgot')}>Forgot password?
)} {turnstile}
New here? switchMode('register')}>Create an account
)} {mode === 'register' && ( <>
Username
setUsername(e.target.value)} style={{ marginBottom: 16 }} /> Shown on your reports and comments, exactly as you type it. {emailOn && ( <>
Email (optional)
setEmail(e.target.value)} style={{ marginBottom: 16 }} /> Only used to recover your account, never shown publicly. We'll ask you to confirm it. )} {turnstile} {passkeys && ( <> )}
Password
setPassword(e.target.value)} style={{ marginBottom: 16 }} />
Already have an account? switchMode('login')}>Sign in
)} {mode === 'forgot' && ( <>
Username or email
setLogin(e.target.value)} style={{ marginBottom: 24 }} /> {turnstile}
Remembered it? switchMode('login')}>Sign in
)} {mode === 'forgot-sent' && ( )} {mode === 'reset' && ( <>
New password
setPassword(e.target.value)} style={{ marginBottom: 24 }} placeholder="At least 8 characters" /> )}
); } // ── Account security (profile page) ─────────────────────────── function AccountSecurity({ user, onUserChange }) { const [keys, setKeys] = React.useState(null); const [error, setError] = React.useState(''); const [note, setNote] = React.useState(''); const [email, setEmail] = React.useState(user.email || ''); const [currentPw, setCurrentPw] = React.useState(''); const [newPw, setNewPw] = React.useState(''); const passkeys = window.api.passkeysSupported(); const [emailOn, setEmailOn] = React.useState(false); const loadKeys = () => window.api.listPasskeys().then(r => setKeys(r.passkeys)).catch(() => setKeys([])); React.useEffect(() => { loadKeys(); window.api.getConfig().then(c => setEmailOn(!!c.emailEnabled)).catch(() => {}); }, []); const act = async (fn, fallback) => { setError(''); setNote(''); try { await fn(); } catch (err) { setError(passkeyError(err, fallback)); } }; const addPasskey = () => act(async () => { await window.api.addPasskey(navigator.platform ? `Passkey (${navigator.platform})` : 'Passkey'); await loadKeys(); setNote('Passkey added.'); }, 'Could not add the passkey'); const removePasskey = (id) => act(async () => { await window.api.removePasskey(id); await loadKeys(); }, 'Could not remove the passkey'); const saveEmail = () => act(async () => { const updated = await window.api.setEmail(email.trim()); onUserChange(updated); setNote(updated.email ? `Check ${updated.email} for a confirmation link.` : 'Email removed.'); }, 'Could not update the email'); const savePassword = () => act(async () => { if (newPw.length < 8) throw new Error('Password must be at least 8 characters'); onUserChange(await window.api.setPassword({ currentPassword: currentPw, newPassword: newPw })); setCurrentPw(''); setNewPw(''); setNote('Password saved.'); }, 'Could not save the password'); const row = { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 16, padding: '12px 0', borderBottom: '1px solid var(--line)', fontSize: 13 }; return (
ACCOUNT SECURITY
Signed in as @{user.username}
{note &&
{note}
}
Passkeys
{keys === null ?
Loading…
: ( <> {keys.length === 0 &&
No passkeys yet.
} {keys.map(k => (
{k.name} · added {k.created_at?.slice(0, 10)}{k.last_used_at ? ` · last used ${k.last_used_at.slice(0, 10)}` : ''}
))} )} {passkeys ? :
This browser doesn't support passkeys.
} {(emailOn || user.email) && ( <>
Email (optional)
{user.email ? (user.emailVerified ? 'Confirmed: usable for sign-in and password resets.' : 'Waiting for confirmation: check your inbox.') : 'No email: your account can only be recovered with a passkey or password.'}
setEmail(e.target.value)} />
)} {!emailOn && !user.email && (
There's no password reset by email here, so keep a second way in: add a passkey on another device, or a password.
)}
{user.hasPassword ? 'Change password' : 'Add a password'}
{user.hasPassword && ( setCurrentPw(e.target.value)} style={{ marginBottom: 8 }} /> )}
setNewPw(e.target.value)} />
); } window.SignInModal = SignInModal; window.AccountSecurity = AccountSecurity;