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
Sign-in: a reload after the session ended still says the changes are kept, while the copy owes its account any
Duarte Santosd95a178917b0
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex 510d31c6f..1532fa8e4 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -1030,11 +1030,13 @@ export const useStore = create((set, get) => {} catch (e) {// The session ended (expired, revoked, signed out everywhere): back to the sign-in// screen, which says so. The copy stays here with its owner, and signing in again as the- // same account merges it (adoptProfile).+ // same account merges it (adoptProfile). A later reload still says so while that copy+ // owes its account changes — the user is gone by then, the owner and the copy are not —+ // unless whoever is here chose to go on as a guest.if (e.status === 401) {- const had = !!get().user+ const kept = !!get().user || (!get().isGuest() && !!localStorage.getItem('gym_owner') && owes())get().setUser(null)- if (had) failed(e, { pending: owes() })+ if (kept) failed(e, { pending: owes() })}// Started without a network (a home-screen app reopened in the gym's basement), or// behind a proxy answering for the server: keep the signed-in copy and say so from thediff --git a/frontend/src/store/useStore.sync-status.test.jsx b/frontend/src/store/useStore.sync-status.test.jsxindex 2d8c22eb6..5750018cc 100644--- a/frontend/src/store/useStore.sync-status.test.jsx+++ b/frontend/src/store/useStore.sync-status.test.jsx@@ -121,13 +121,13 @@ describe('sync status', () => {})describe('the web boot', () => {- const boot = async me => {+ const boot = async (me, user = USER) => {api.mockImplementation(async path => {if (path === '/api/config') return { allow_guest: true }if (path === '/api/me') return me()throw new Error('unexpected ' + path)})- useStore.setState({ user: USER, ready: false })+ useStore.setState({ user, ready: false })await useStore.getState().boot()}@@ -142,6 +142,23 @@ describe('the web boot', () => {expect(useStore.getState().sync.status).toBe('local')})+ it('a reload after that still says so while the copy owes its account changes — not once a guest chose to go on', async () => {+ useStore.setState({ S: { ...clone(DEF), _ts: 100, workouts: [workout('w1')] } })+ localStorage.setItem('gym_dirty', '1')+ await boot(() => { throw httpError(401) }, null)+ expect(useStore.getState().sync).toMatchObject({ status: 'auth', pending: true, lastError: { status: 401 } })++ useStore.getState().setGuest(true)+ await boot(() => { throw httpError(401) }, null)+ expect(useStore.getState().sync.status).toBe('local')+ })++ it('a reload with nothing owed is simply signed out', async () => {+ useStore.setState({ S: { ...clone(DEF), _ts: 100, workouts: [workout('w1')] } })+ await boot(() => { throw httpError(401) }, null)+ expect(useStore.getState().sync.status).toBe('local')+ })+it('a page in front that answers for the server is an error, not a sign-out', async () => {await boot(() => { throw Object.assign(new Error('not openGym data'), { status: 200, code: 'bad-response' }) })expect(useStore.getState().user).toEqual(USER)