From a5e360cde56f465a291e0cf1a7fe0a9b1f18f92c Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sat, 1 Aug 2026 16:52:30 +0200 Subject: [PATCH] Settings can register on an invite-only instance too The sign-in screen asks for an invite code when the server says it needs one. The same registration reached from Settings never did: it collected a name, called passkeyRegister without the second argument, and the server refused it. On an invite-only instance that path could not succeed at all, with nothing on screen to explain why. It now reads /api/config and shows the code field on the same terms, reusing the sign-in screen's own strings so nothing new needs translating. --- frontend/src/views/Settings.jsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx index 078db65..4b3508c 100644 --- a/frontend/src/views/Settings.jsx +++ b/frontend/src/views/Settings.jsx @@ -4,7 +4,7 @@ import { useStore, DEF, hasData } from '../store/useStore.js' import { useUI } from '../store/useUI.js' import { ACCENTS, todayISO, localTZ } from '../lib/format.js' import { effortOf } from '../lib/history.js' -import { webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js' +import { api, webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js' import { pushSupported, enablePush, disablePush, sendTestPush } from '../lib/push.js' import { wakeLockSupported } from '../lib/wakelock.js' import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js' @@ -327,13 +327,20 @@ function PushCard({ S, update, toast }) { } +// The same registration as the sign-in screen's, reached from Settings instead. It asks for +// the invite code on the same terms: an invite-only instance rejects a registration without +// one, so a form that cannot collect it is a form that cannot succeed. function RegisterInline({ close, setUser, pushState, pullState, toast }) { const nameRef = useRef(null) + const [code, setCode] = useState('') + const [inviteOnly, setInviteOnly] = useState(false) + useEffect(() => { api('/api/config').then(c => setInviteOnly(!!c.invite_only)).catch(() => {}) }, []) const go = async () => { const n = (nameRef.current.value || '').trim() if (!n) { toast(t('Enter a name')); return } + if (inviteOnly && !code.trim()) { toast(t('An invite code is required')); return } try { - const u = await passkeyRegister(n); setUser(u); close() + const u = await passkeyRegister(n, code.trim()); setUser(u); close() if (hasData(useStore.getState().S)) { await pushState(); toast(t('Profile created — data moved into it')) } else { await pullState(); toast(t('Welcome, {0}', u.name)) } } catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || t('Registration failed')) } @@ -342,6 +349,12 @@ function RegisterInline({ close, setUser, pushState, pullState, toast }) {

{t('Create your profile')}

{t('Pick a name, then confirm with your device.')}
+ {inviteOnly && <> +
+ setCode(e.target.value.toUpperCase())} style={{ letterSpacing: '.14em', fontWeight: 600, textAlign: 'center' }} /> +
{t('This app is invite-only — enter the code you were given.')}
+ }
}