Skip to content

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.

Merge the password sign-in branch: a name and password next to passkeys when the instance sets PASSWORD_LOGIN, a sign-in throttle in front of the password routes, and admin reset codes (#118)

Duarte Santosa71eb623fc53
diff --cc api/openapi.yaml
index e1e6b5af7,049548559..950177455
--- a/api/openapi.yaml
+++ b/api/openapi.yaml
@@@ -121,20 -145,10 +149,21 @@@ paths
get:
tags: [meta]
operationId: getConfig
- summary: Public instance configuration
+ summary: Instance configuration
description: |
The flags the login screen needs before anyone is signed in. Both reflect
-- environment variables on the server (`INVITE_ONLY`, `ALLOW_GUEST`).
++ environment variables on the server (`INVITE_ONLY`, `ALLOW_GUEST`), and so does
++ `password_login`, which is there only when `PASSWORD_LOGIN=1`.
+
+ A caller with a valid session also gets a `coach` key: the block when the
+ instance has the AI Coach switched on **and** a provider connected, and `null`
+ when it has not. A caller with no session gets no key at all — the block names
+ the provider this instance talks to, which is the same fact
+ `GET /api/coach/disclosure` will not hand out unauthenticated.
+
+ The key is always present for a session, `null` included, so a client that
+ caches this answer can tell "no Coach on this instance" from "you were not
+ signed in when you asked" and knows whether asking again would change it.
security: []
responses:
'200':
@@@ -152,33 -166,14 +181,41 @@@
description: >-
When false, the client hides "continue without account".
Guest mode is purely client-side and never calls this API.
+ coach:
+ description: >-
+ Present for a signed-in caller and absent otherwise; `null` when this
+ instance has no Coach enabled and connected. Every Coach entry point
+ in the client hangs off the block being there.
+ type: ['object', 'null']
+ properties:
+ enabled: { type: boolean, const: true }
+ provider:
+ type: string
+ description: Provider id, e.g. `anthropic`, `compatible`, `fixture`.
+ providerLabel: { type: string, description: Human-readable provider name. }
+ authMode:
+ type: string
+ enum: [instance, profile]
+ description: Whose credential the jobs spend.
+ community:
+ type: boolean
+ description: Whether "compare with others" is offered on this instance.
+ password_login:
+ type: boolean
+ const: true
+ description: >-
+ Present (and true) only when the instance runs with
+ PASSWORD_LOGIN=1 — the client then offers name-and-password
+ sign-in next to passkeys.
- example: { invite_only: true, allow_guest: false, password_login: true }
+ examples:
+ anonymous: { value: { invite_only: true, allow_guest: false } }
+ signedInNoCoach: { value: { invite_only: true, allow_guest: false, coach: null } }
+ signedIn:
+ value:
+ invite_only: true
+ allow_guest: false
+ coach: { enabled: true, provider: compatible, providerLabel: "OpenAI-compatible endpoint", authMode: instance, community: false }
++ passwordLogin: { value: { invite_only: true, allow_guest: false, password_login: true } }
/api/me:
get:
@@@ -1741,48 -1501,43 +2091,85 @@@ components
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "forbidden" }
+ CoachOff:
+ description: >-
+ The Coach is not set up on this instance — switched off, or no provider connected.
+ Every Coach route answers this rather than pretending, so an unconfigured instance
+ renders exactly the app it was before the feature existed.
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Error' }
+ example: { error: "the Coach is not set up on this instance" }
+ CoachJobQueued:
+ description: >-
+ Queued. The job runs in the background; its outcome arrives through
+ `GET /api/coach/status`, which the client polls.
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ job:
+ type: object
+ properties:
+ id: { type: string, description: 16 hex characters. }
+ example: { job: { id: "9f1c2d3e4a5b6c7d" } }
+ CoachRefused:
+ description: |
+ The Coach will not take this job, and says which reason in `code`:
+
+ - `busy` (409) — a job for this profile is already running.
+ - `shared` (409) — instance mode, and the credential belongs to another profile.
+ - `cap` (429) — this profile's or the instance's daily limit is spent.
+ - `consent` (403) — no consent recorded for this profile.
+ - `unprivileged` (503) — the privilege drop cannot be performed, so no job runs.
+
+ The message is the one to show; the raw provider detail never reaches the user.
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ error: { type: string }
+ code: { type: string, enum: [off, busy, cap, consent, shared, unprivileged] }
+ example: { error: "the Coach is already thinking about your training", code: busy }
+ TooManyRequests:
+ description: >-
+ Paused by the sign-in throttle (see *Throttling* in the description). The request
+ was not looked at; try again after `Retry-After` seconds.
+ headers:
+ Retry-After:
+ description: Seconds until the pause ends.
+ schema: { type: integer }
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Error' }
+ example: { error: "too many attempts — try again later", code: "locked", retryAfter: 60 }
+ Busy:
+ description: Every password check slot and the short queue behind them are taken.
+ headers:
+ Retry-After:
+ schema: { type: integer }
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Error' }
+ example: { error: "the server is busy — try again in a moment", code: "busy" }
+ PasswordPolicy:
+ description: >-
+ The new password breaks the policy — `too-short` (under 10 characters),
+ `too-long` (over 256) or `too-common` — or a field is `missing`.
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Error' }
+ example: { error: "this password is too easy to guess", code: "too-common" }
+ NameTaken:
+ description: >-
+ Another profile already signs in with this name, or holds it with a reset code
+ that has not been used or expired yet.
+ content:
+ application/json:
+ schema: { $ref: '#/components/schemas/Error' }
+ example: { error: "another profile already signs in with this name", code: "name-taken" }
schemas:
Error:
diff --cc api/server.js
index b87f3c9c8,81fdf8fc2..9457e366a
--- a/api/server.js
+++ b/api/server.js
@@@ -723,24 -1116,8 +1144,26 @@@ const routes =
// single flag every piece of Coach UI hangs off, so an unconfigured instance is byte-for-byte
// the app it was before the feature existed.
'GET /api/config': async (req, res) => {
- const coach = coachConfig.publicConfig();
- json(res, 200, { invite_only: INVITE_ONLY, allow_guest: ALLOW_GUEST, ...(PASSWORD_LOGIN ? { password_login: true } : {}), ...(coach ? { coach } : {}) });
+ // The Coach block names the provider this instance is wired to — the same fact
+ // /api/coach/disclosure refuses to hand out without a session, and for the same reason: on an
+ // invite-only instance, which model this box talks to is nobody's business who has not been
+ // let in. The two flags above it are what the login screen and the pre-login boot read
+ // (invite code field, "continue without account"), so those stay public.
+ //
+ // Every Coach consumer on the client side already requires a signed-in user before it looks
+ // at this block (lib/coach.js coachAvailable), so nothing that could render loses anything.
+ //
+ // A signed-in caller always gets the key, even on an instance with no Coach, where it is
+ // null. The client caches this answer for the page load and has to know whether the copy it
+ // holds was made for a session: without the key it cannot tell "no Coach here" from "you
+ // were not signed in when you asked", and would re-ask on every sign-in on every instance
+ // that has no Coach. The key's absence is that answer.
+ json(res, 200, {
+ invite_only: INVITE_ONLY, allow_guest: ALLOW_GUEST,
++ // Only when on, so an instance without passwords answers exactly as it did before (#118).
++ ...(PASSWORD_LOGIN ? { password_login: true } : {}),
+ ...(readSession(req) ? { coach: coachConfig.publicConfig() } : {})
+ });
},
// A paired phone's token was minted once, at pairing, and nothing ever renewed it: after
@@@ -1326,9 -1691,16 +1758,17 @@@ const server = http.createServer(async
console.warn('refused cross-origin', key, 'origin=' + req.headers.origin, 'expected=' + ORIGIN);
return json(res, 403, { error: 'cross-origin request refused' });
}
+ // After the origin check, so a forged request spends nobody's budget. The password routes only
+ // (see the sign-in throttle above).
+ if (key in THROTTLED) {
+ const addr = limitAddress(req);
+ const kind = THROTTLED[key];
+ const wait = AUTH_BURST.take(addr) || (kind ? ADDR_FAILS.retryAfter(kind + '|' + addr) : 0);
+ if (wait) return tooMany(res, wait);
+ }
try { await handler(req, res); }
catch (e) {
+ if (e?.clientGone) { console.warn(key, 'client went away mid-body:', e.message); return; }
if (e instanceof HttpError) {
if (!res.headersSent) json(res, e.status, { error: e.message });
return;
diff --cc frontend/src/lib/pt-br-locale.test.js
index 0a016630c,929fed922..8aafbe551
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@@ -27,21 -27,11 +27,21 @@@ describe('Brazilian Portuguese locale'
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
- expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(721)
- expect(inherited).toHaveLength(677)
- // If this fails, review the changed keys and wording before accepting a new hash. From
+ // Every override names a real source string, so the two sets partition pt-PT's keys between
+ // them and the fingerprint below covers everything not overridden. A typo'd override key
+ // would otherwise sit in the file translating nothing.
+ const stray = Object.keys(PT_BR_OVERRIDES).filter(key => !(key in pt))
+ expect(stray, 'override keys that are not pt-PT keys').toEqual([])
+ expect(Object.keys(PT_BR_OVERRIDES).length + inherited.length).toBe(Object.keys(pt).length)
+ // …and each one really reaches the pack, whatever the spread order does.
+ for (const [key, value] of Object.entries(PT_BR_OVERRIDES)) expect(ptBR[key], key).toBe(value)
+
+ // The counts themselves are read off the pack rather than pinned here: a new UI string lands
+ // in pt.js and pt-BR.js together and moves both, and a number in a test that every new string
+ // has to be taught is a number nobody reads. What the numbers stood for is asserted above.
+ // If the hash fails, review the changed keys and wording before accepting a new one. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('fb67e0870032b779637f003205443fe51a060d68f763b7c8b75d8b943956bfa6')
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('4d451f4281754e48e4e5d41bf9a4327d8931ef91b7b2a9905b6d5422d3d9951c')
++ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('f0c4ce10b8f883ab04b9bfb37590a4fd4efd27732fa15ade1cb4619fe01ac3c9')
})
test('does not leak European Portuguese UI terms', () => {
diff --cc frontend/src/views/Admin.jsx
index 1b8906c6a,792036dfb..bfd8434eb
--- a/frontend/src/views/Admin.jsx
+++ b/frontend/src/views/Admin.jsx
@@@ -67,9 -94,11 +94,11 @@@ function UserDetail({ id, onChanged, cl
{u.admin && <span className="adm-pill acc">admin</span>}
{u.disabled && <span className="adm-pill bad">disabled</span>}
{u.invitedBy && <span className="adm-pill">invite {u.invitedBy}</span>}
+ {u.password && <span className="adm-pill">password</span>}
+ {u.resetUntil && <span className="adm-pill acc">reset code until {new Date(u.resetUntil).toLocaleString()}</span>}
<span className="adm-pill">joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'}</span>
</div>
- <div className="tiles" style={{ textAlign: 'left' }}>
+ <div className="tiles" style={{ textAlign: 'start' }}>
<div className="tile"><div className="l">Workouts</div><div className="v" style={{ fontSize: '1.1rem' }}>{workouts.length}</div></div>
<div className="tile"><div className="l">Weigh-ins</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.bodyweight.length}</div></div>
<div className="tile"><div className="l">Routines</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.routines.length}</div></div>
diff --cc frontend/src/views/Login.jsx
index c3a4fe3cf,0a7c71b85..dc273f315
--- a/frontend/src/views/Login.jsx
+++ b/frontend/src/views/Login.jsx
@@@ -83,9 -102,18 +102,18 @@@ export default function Login()
{webauthnOK() ? <>
<Button variant="primary" icon="person" onClick={signIn}>{t('Sign in with passkey')}</Button>
<div style={{ height: 10 }} />
- <Button icon="sparkles" onClick={() => useUI.getState().openSheet(close => <RegisterSheet close={close} />)}>{t('Create new profile')}</Button>
+ {pwOn && <><Button icon="key" onClick={() => openPasswordSignIn()}>{t('Sign in with password')}</Button><div style={{ height: 10 }} /></>}
+ <Button icon="sparkles" onClick={register}>{t('Create new profile')}</Button>
+ {canGuest && <div style={{ height: 10 }} />}
+ </> : pwOn ? <>
+ {/* Plain http on a LAN address, or a browser without passkey support: the password is
+ the way in, and the only way to create a profile from here. */}
+ <div className="card small muted" style={{ textAlign: 'left', marginBottom: 14 }}>{t("This browser doesn't support passkeys — sign in with your name and password instead.")}</div>
+ <Button variant="primary" icon="key" onClick={() => openPasswordSignIn()}>{t('Sign in with password')}</Button>
+ <div style={{ height: 10 }} />
+ <Button icon="sparkles" onClick={register}>{t('Create new profile')}</Button>
{canGuest && <div style={{ height: 10 }} />}
- </> : <div className="card small muted" style={{ textAlign: 'left' }}>{canGuest
+ </> : <div className="card small muted" style={{ textAlign: 'start' }}>{canGuest
? t("This browser doesn't support passkeys — you can still use openGym locally on this device.")
// Without passkeys and without the guest entrance there is no way in from this browser,
// so say that plainly instead of offering a local profile that cannot be created.
diff --cc frontend/src/views/Settings.jsx
index 6a75b605d,96c027abe..053f5527c
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@@ -228,12 -229,18 +231,19 @@@ export default function Settings()
{user.admin && <Row icon="wrench" iconTint="var(--indigo)" title={t('Admin dashboard')} accessory="chevron" onClick={() => nav('/admin')} />}
<Row icon="link" iconTint="var(--blue)" title={t('Pair the mobile app')} subtitle={t('Connect the openGym app on your phone to this account.')} accessory="chevron"
onClick={() => useUI.getState().openSheet(close => <PairSheet close={close} />)} />
+ {pwOn && <PasswordRow />}
<Row icon="signOut" iconTint="var(--red)" title={t('Sign out')} danger onClick={signOutHere} />
<Row icon="shield" iconTint="var(--red)" title={t('Sign out everywhere')} subtitle={t('Ends this profile’s sessions on all your devices.')} danger onClick={signOutEverywhere} />
+ <AccountIdRow id={user.id} />
</> : webauthnOK() ? <>
<Row icon="sparkles" iconTint="var(--acc)" title={t('Create passkey profile')} subtitle={t('Keeps your data safe and separate per person.')} accessory="chevron" onClick={registerHere} />
- <Row icon="person" iconTint="var(--blue)" title={t('Sign in with passkey')} accessory="chevron" onClick={signInAgain} />
+ <Row icon="person" iconTint="var(--blue)" title={t('Sign in with passkey')} accessory="chevron" onClick={passkeySignIn} />
+ {pwOn && <Row icon="key" iconTint="var(--orange)" title={t('Sign in with password')} accessory="chevron" onClick={() => openPasswordSignIn()} />}
+ <KeptChangesRows />
+ </> : pwOn ? <>
+ {/* No passkeys in this browser (plain http on a LAN address, say): a password is the way in. */}
+ <Row icon="sparkles" iconTint="var(--acc)" title={t('Create new profile')} subtitle={t('Keeps your data safe and separate per person.')} accessory="chevron" onClick={openPasswordRegister} />
+ <Row icon="key" iconTint="var(--orange)" title={t('Sign in with password')} accessory="chevron" onClick={() => openPasswordSignIn()} />
<KeptChangesRows />
</> : <>
<Row icon="lock" iconTint="var(--grey)" title={t('Passkeys not supported in this browser.')} />