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
Merge #249: fix(api): requests the API blamed itself for, a cache with no bound, and a weekly review that could miss its week (kurktchiev)
Duarte Santos1b7f5fa19b7a
diff --cc api/server.jsindex 716c13d49,ca97e4ddb..b87f3c9c8--- a/api/server.js+++ b/api/server.js@@@ -695,23 -717,30 +723,39 @@@ 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, ...(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,+ ...(readSession(req) ? { coach: coachConfig.publicConfig() } : {})+ });},+ // A paired phone's token was minted once, at pairing, and nothing ever renewed it: after+ // SESSION_DAYS the server refused a phone that had been in use every day. The phone asks this+ // on every start, so once its token is past half its life the answer carries a new one+ // (`token`), which the phone saves in place of the old. makeSession() writes the account's+ // current session version into it, so "sign out everywhere" ends a renewed token exactly as it+ // ended the old one — and a revoked token never gets this far. A browser's cookie is left+ // alone: signing in renews it, as before.'GET /api/me': async (req, res) => {- const user = readSession(req);- if (!user) return json(res, 401, { error: 'not signed in' });- json(res, 200, { user: { id: user.id, name: user.name, admin: isAdmin(user) } });+ const s = sessionOf(req);+ if (!s) return json(res, 401, { error: 'not signed in' });+ const { user } = s;+ const renew = s.bearer && s.exp - Date.now() < SESSION_DAYS * 86400000 / 2;+ json(res, 200, { user: { id: user.id, name: user.name, admin: isAdmin(user) }, ...(renew ? { token: makeSession(user) } : {}) });},'POST /api/register/options': async (req, res) => {diff --cc frontend/src/store/useStore.jsindex fed65e636,43a377eec..c25e411cc--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@@ -693,28 -378,26 +701,35 @@@ export const useStore = create((set, ge// The local copy belongs to whoever last signed in here. When a session expires or is// revoked elsewhere, boot() only drops the user and the data stays; a different profile// signing in next must not inherit it (pullState would push it into that account, and- // carry the in-progress workout along). A proper sign-out clears the owner, so a guest's- // data still moves into a freshly created profile.+ // carry the in-progress workout along) — what it still owed its own account is kept aside+ // for that account first (keepForPrevious). A proper sign-out clears the owner, so a guest's+ // data still moves into a freshly created profile. The same account coming back — a+ // phone paired again, a browser signed in again — is remembered for adoptProfile.const owner = localStorage.getItem('gym_owner')- if (owner && owner !== u.id) {- localStorage.removeItem('gym_dirty')- localStorage.removeItem(SYNC_KEY)+ rejoined = owner === u.id+ const other = !!owner && owner !== u.id+ if (other) {+ keepForPrevious(owner)+ forgetSync()localStorage.removeItem(KEY)persist(clone(DEF), false)+ setSync({ pending: false, lastSynced: 0, lastError: null })}+ localStorage.setItem('gym_owner_name', u.name || '')localStorage.setItem('gym_owner', u.id)localStorage.setItem('gym_user', JSON.stringify(u)); localStorage.removeItem('gym_guest')+ // The file follows at once, as the new account's: until then it holds the previous one's.+ if (other && MOBILE) nativePersist(true)+ // The server answers /api/config with a `coach` key only to a session — the block, or+ // null on an instance that has no Coach. So a copy with no key at all is one fetched+ // before this sign-in (boot's, or the login screen asking for invite_only), and every+ // Coach entry point would stay hidden until the next reload. Ask again, unawaited:+ // nothing on this path waits for the answer. A copy that has the key was made for a+ // session and is already the right answer, Coach or no Coach.+ if (get().config && !('coach' in get().config)) get().refreshConfig()- } else localStorage.removeItem('gym_user')+ } else { rejoined = false; localStorage.removeItem('gym_user') }set({ user: u })+ setSync({})},// One PUT at a time: a push asked for while one is in flight runs after it (once, however