Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Delete account: the last admin hears why before any prompt
Duarte Santos56d96a14f9d8
diff --git a/api/openapi.yaml b/api/openapi.yamlindex 713191645..aee8eb459 100644--- a/api/openapi.yaml+++ b/api/openapi.yaml@@ -3367,6 +3367,14 @@ components:lastWayIn:type: booleandescription: Removing any one passkey would be refused (409 `last-way-in`).+ deleteBlocked:+ type: string+ enum: [last-admin]+ description: >-+ Present when deleting this profile (`POST /api/account/delete`) would be refused+ before any proof is checked: `last-admin`, the only admin while other profiles+ remain. The delete sheet says so before asking for a passkey or the password; the+ delete itself still checks.example:passkeys: [{ id: "g3Xq…", name: "Laptop", created: "2026-09-23T10:00:00.000Z", lastUsed: "2026-09-23T10:00:00.000Z", transports: [internal] }]password: falsediff --git a/api/server.js b/api/server.jsindex 26aaf5dad..ff6b19f11 100644--- a/api/server.js+++ b/api/server.js@@ -1670,6 +1670,9 @@ const passwordRoutes = {// Sessions are not tied to the passkey that opened them — a session is `uid:expiry:version`,// nothing more — so removing a passkey stops it signing in again but does not end a session it// already opened. "Sign out everywhere" does that, and Settings says so where a passkey is removed.+// The last admin may not delete their own profile while anyone else is on the instance: nobody+// could run it from the app afterwards. Alone on it, they may go.+const lastAdminLeaving = u => isAdmin(u) && db.users.length > 1 && db.users.filter(isAdmin).length <= 1;const passkeyState = u => {const passkeys = listPasskeys(db, u.id);// `password`: whether the password can confirm an addition or a removal (proveOwner) — only@@ -1726,7 +1729,9 @@ const passkeyRoutes = {'GET /api/account/passkeys': async (req, res) => {const user = readSession(req);if (!user) return notSignedIn(res);- json(res, 200, passkeyState(user));+ // `deleteBlocked`: the profile's own delete would be refused before any proof is looked at,+ // so the delete sheet says so up front instead of after a passkey or password prompt.+ json(res, 200, { ...passkeyState(user), ...(lastAdminLeaving(user) ? { deleteBlocked: 'last-admin' } : {}) });},// Adding one from Settings, step one: the proof, then the options. The proof is spent here; the@@ -2300,7 +2305,7 @@ const routes = {if (typeof body.name !== 'string' || body.name.trim() !== user.name) {return json(res, 400, { error: 'type the account name to confirm', code: 'confirm-name' });}- const lastAdmin = () => isAdmin(user) && db.users.length > 1 && db.users.filter(isAdmin).length <= 1;+ const lastAdmin = () => lastAdminLeaving(user);const refuseLastAdmin = () => json(res, 409, { error: 'the last admin cannot leave while other profiles remain', code: 'last-admin' });if (lastAdmin()) return refuseLastAdmin();const proof = s.bearer && !passwordWayIn(user) ? 'device' : await proveOwner(req, res, user, body, 'account-delete');diff --git a/api/test/server-account-delete.test.js b/api/test/server-account-delete.test.jsindex 0543eced0..ae811f4ba 100644--- a/api/test/server-account-delete.test.js+++ b/api/test/server-account-delete.test.js@@ -121,6 +121,22 @@ test('the last admin cannot leave while other profiles remain, proof or not', asassert.equal(h.db().users.length, 2, 'nothing was removed');});+test('the delete sheet learns of the last-admin refusal before it asks for any proof', async t => {+ const h = await startServer(t, { users: ['admin', 'user', 'admin2'] });+ const info = async uid => (await fetch(`${h.api}/api/account/passkeys`, { headers: as(uid) })).json();+ assert.equal((await info(ADMIN)).deleteBlocked, undefined, 'another admin remains: nothing blocks');+ assert.equal((await info(USER)).deleteBlocked, undefined, 'a plain profile is never blocked');+ assert.equal((await h.del(ADMIN2, { name: h.db().users.find(u => u.id === ADMIN2).name, current: GOOD })).status, 200);+ assert.equal((await info(ADMIN)).deleteBlocked, 'last-admin', 'now the only admin, with a profile left');+ assert.equal((await info(USER)).deleteBlocked, undefined);+});++test('alone on the instance the last admin is not blocked', async t => {+ const h = await startServer(t, { users: ['admin'] });+ const r = await (await fetch(`${h.api}/api/account/passkeys`, { headers: as(ADMIN) })).json();+ assert.equal(r.deleteBlocked, undefined);+});+test('an admin can leave while another admin remains', async t => {const h = await startServer(t, { users: ['admin', 'admin2', 'user'] });assert.equal((await h.del(ADMIN, { name: 'Adminna', current: GOOD })).status, 200);diff --git a/frontend/src/components/DeleteAccount.jsx b/frontend/src/components/DeleteAccount.jsxindex b676cc141..3e39a3bab 100644--- a/frontend/src/components/DeleteAccount.jsx+++ b/frontend/src/components/DeleteAccount.jsx@@ -61,6 +61,9 @@ export function DeleteAccountSheet({ close, exportBackup, exportBackupZip, hasMe// there the password says it is you, or, with none, the pairing and the phone's own lock.const passkey = !MOBILE && (proofs?.passkeys?.length || 0) > 0const password = !!proofs?.password+ // The server already knows the delete would be refused (the only admin, with others on the+ // server): said up front, so nobody types their name and answers a passkey prompt for nothing.+ const blocked = proofs?.deleteBlocked === 'last-admin' ? deleteAccountError({ data: { code: 'last-admin' } }) : nullreturn <><h3>{t('Delete your account?')}</h3><div className="muted small" style={{ marginBottom: 14, lineHeight: 1.5 }}>@@ -71,13 +74,13 @@ export function DeleteAccountSheet({ close, exportBackup, exportBackupZip, hasMe{hasMedia && exportBackupZip? <Button icon="share" onClick={exportBackupZip}>{t('Export with photos & videos (.zip)')}</Button>: <Button icon="share" onClick={exportBackup}>{t('Export backup (JSON)')}</Button>}- <form onSubmit={next} noValidate style={{ marginTop: 18 }}>+ {blocked ? <div className="small" role="alert" style={errStyle}>{blocked}</div> : <form onSubmit={next} noValidate style={{ marginTop: 18 }}><label className="small" htmlFor="delete-account-name" style={{ display: 'block', marginBottom: 6 }}>{t('Type {0} to confirm.', name)}</label><input ref={ref} id="delete-account-name" className="input" placeholder={t('Account name')} autoComplete="off"autoCapitalize="none" autoCorrect="off" spellCheck={false} value={typed} onChange={e => setTyped(e.target.value)} /><div style={{ height: 14 }} /><button type="submit" className="btn danger" disabled={!match}>{t('Continue')}</button>- </form>+ </form>}<div style={{ height: 8 }} /><Button variant="ghost" className="dim" onClick={close}>{t('Cancel')}</Button></> : <>diff --git a/frontend/src/components/DeleteAccount.test.jsx b/frontend/src/components/DeleteAccount.test.jsxindex 85d20edde..6652afc6e 100644--- a/frontend/src/components/DeleteAccount.test.jsx+++ b/frontend/src/components/DeleteAccount.test.jsx@@ -170,6 +170,18 @@ describe('DeleteAccountSheet', () => {expect(p.close).not.toHaveBeenCalled()})+ it('the last admin hears why before typing the name or answering a prompt (QA v1.4.2)', async () => {+ mocks.proofs = { passkeys: [{ id: 'k1' }], password: true, deleteBlocked: 'last-admin' }+ const { p, host } = sheet()+ await act(async () => { await Promise.resolve(); await Promise.resolve() })+ expect(alertText(host)).toBe('You’re the only admin here, and other profiles still use this server. Make someone else an admin first.')+ expect(host.querySelector('#delete-account-name')).toBeNull()+ expect([...host.querySelectorAll('button')].map(b => b.textContent)).not.toContain('Continue')+ expect(mocks.passkeyAssertion).not.toHaveBeenCalled()+ expect(mocks.deleteAccount).not.toHaveBeenCalled()+ expect(p.close).not.toHaveBeenCalled()+ })+it('the phone app offers no passkey, which it cannot hold for the server, only the password', async () => {mocks.MOBILE = trueconst { host } = sheet()diff --git a/website/api.html b/website/api.htmlindex fd8d17794..2b4371e6e 100644--- a/website/api.html+++ b/website/api.html@@ -3440,6 +3440,11 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon<span class="p-type">boolean</span><span class="p-desc">Removing any one passkey would be refused (409 <code>last-way-in</code>).</span></div>+ <div class="prow">+ <span class="p-name">deleteBlocked</span>+ <span class="p-type">"last-admin"</span>+ <span class="p-desc">Present when deleting this profile (<code>POST /api/account/delete</code>) would be refused before any proof is checked: <code>last-admin</code>, the only admin while other profiles remain. The delete sheet says so before asking for a passkey or the password; the delete itself still checks.</span>+ </div></div></div></details>