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
Docs: what the connection line on the phone means and what to do about each, where the phone keeps its copies, and that sign out everywhere unpairs phones
Duarte Santos84f3f9ee3015
diff --git a/docs/MOBILE.md b/docs/MOBILE.mdindex 7ef63c3f5..b708c6f12 100644--- a/docs/MOBILE.md+++ b/docs/MOBILE.md@@ -29,16 +29,58 @@ that's already signed in: Settings → **"Pair the mobile app"** shows a one-tim5 minutes); enter your server's address and that code in the app (same first-launch screen,or Settings → **"Connect to my server"** later) to finish. Notes:-- Requires network access every time the app is used — there's no offline file mirror once- connected, same as the browser PWA.+- Works offline too: the phone keeps its copy (and the file mirror) while connected, and+ changes made without a network go to the server as soon as it is reachable again.- Use an HTTPS address if at all possible: the connection carries a bearer token instead ofa cookie, and that token would otherwise cross the network in plain text.+- The token lasts `SESSION_DAYS` (90 by default, see `docs/SELF_HOSTING.md`) and renews+ itself: every time the app starts, a token past half its life is swapped for a fresh one.+ A phone that is used at all never runs out; one left unopened for longer than+ `SESSION_DAYS` has to be paired again.- "Sign out everywhere" (Settings → Account, in the browser) revokes a paired app's accesstoo — it's the same signed session token either way, just delivered over a header instead- of a cookie. See `/api/pair/create` and `/api/pair/redeem` in `api/server.js` for the- exchange itself.-- Settings → "Disconnect" syncs one last time, then drops the device cleanly back to local- mode.+ of a cookie. The phone has no passkey to sign back in with, so it has to be **paired+ again**; nothing on it is lost meanwhile (see below). See `/api/pair/create` and+ `/api/pair/redeem` in `api/server.js` for the exchange itself.+- Settings → "Disconnect" first checks that your server has every change. If it has, the+ phone drops cleanly back to local mode. If not, it says how many changes are missing and+ offers **Try again**, **Export backup**, or **Disconnect anyway** — which keeps those+ changes on the phone and adds them back the next time it is paired with the same server+ and account.++### Connection states++Settings → **Server & sync** shows the server, the account, how things stand, when the phone+last held exactly what the server holds, how many changes are still waiting, and a **Sync+now** button that says how it went. Whenever the app is *not* connected, a line under the+status bar says so on every screen, and stays until the condition is gone:++| The line says | What it means | What to do |+|---|---|---|+| *Offline — your changes are saved on this device…* | No answer at all: no network, the server is down, or it did not answer within 20 s (60 s for an upload). | Nothing — it syncs by itself once the server is reachable. **Try again** checks at once. |+| *Your server answered with an error (HTTP 502)…* | The server (or the proxy in front of it) answered with an error. The code is the one the server sent. | Check the server and its proxy logs; **Try again** once it is back. A 413 means the proxy's upload limit is too small (`client_max_body_size`). |+| *Your server's address answered with something other than openGym (HTTP 200)…* | Something else answered in the server's place — typically a proxy's sign-in page or a catch-all that serves the web app for `/api/*`. | Let `/api/*` through to the openGym API unchanged, including the `Authorization` header. |+| *Your server no longer accepts this phone…* | The server refused the phone's token (401): "sign out everywhere", the account disabled, a `data/secret` that was replaced, a token older than `SESSION_DAYS`, or a proxy with its own login that rejects `Authorization: Bearer`. | **Pair again**: in a signed-in browser open Settings → "Pair the mobile app" and enter the new code. The address is already filled in. |+| *This phone is no longer paired with your server…* | A phone that an earlier version of the app unpaired by itself after its token was refused. The address is gone. | **Pair again**, typing the address. |+| *On this phone only — not connected to a server* | Local mode, chosen at first launch or after Disconnect. Said quietly. | Nothing, or **Connect** to pair with a server. |++In every one of these states the phone keeps its data and every change you make. Pairing+again with the **same account** merges what the phone kept with what the server has — new+workouts from both sides, the later edit of each routine, the newer copy's settings — and+nothing needs to be exported first. Pairing with a *different* account keeps the first+account's unsent changes aside on the phone until that account comes back.++Where the phone keeps things, in case you ever need them by hand:++- `opengym-state.json` in the app's private data directory — the durable copy of everything+ on the phone, written after every change (not reachable without a rooted phone or `adb`+ on a debug build).+- `opengym-stash.json`, same directory — changes kept by "Disconnect anyway" or by another+ account pairing, waiting for their server and account.+- `Documents/opengym-backup-YYYY-MM-DD.json` — only with Settings → **Auto-backup on+ changes** switched on: a dated copy after every finished workout or edited routine, in the+ phone's Documents folder where a file manager or a sync app can reach it. Settings →+ **Import backup** reads it back.## Prerequisitesdiff --git a/docs/SELF_HOSTING.md b/docs/SELF_HOSTING.mdindex e256873fd..da401d0ca 100644--- a/docs/SELF_HOSTING.md+++ b/docs/SELF_HOSTING.md@@ -51,7 +51,12 @@ you're poking at the API directly:- `POST /api/pair/create` (needs a session) and `POST /api/pair/redeem` (doesn't) implementthis — see `api/server.js`. The returned token is the exact same signed value a cookie- carries, so "sign out everywhere" invalidates it too.+ carries, so "sign out everywhere" invalidates it too — and a phone has no passkey to sign+ back in with, so every paired phone has to be **paired again** afterwards. The phone says+ so ("Your server no longer accepts this phone") and keeps its data until it is.+- The token lasts `SESSION_DAYS` like a cookie, but renews itself: `GET /api/me`, which the+ app calls on every start, answers a bearer token past half its lifetime with a fresh+ `token` carrying the account's current session version. Revocation is unaffected.- The server reflects `Access-Control-Allow-Origin` for any request that sends an `Origin`header, so the app's own WebView origin can call the API cross-origin. It never sends`Access-Control-Allow-Credentials`, so this doesn't let a browser read your cookie session@@ -193,6 +198,11 @@ resolver does not fail fast — every `/api` request hangs until it times out. Oit to the cluster DNS service address (`kubectl -n kube-system get svc kube-dns`, commonly`10.96.0.10`); under Podman, to whatever its network provides.+`SESSION_DAYS` is how long a browser sign-in and a phone pairing last, counted from when they+were issued; lowering it never cuts an existing session short. A browser renews its session by+signing in; a paired phone renews its token by itself whenever it starts past half of that+time, so only a phone left unopened for longer than `SESSION_DAYS` has to be paired again.+The web image renders its nginx config from these when the container starts, so they take effecton a **prebuilt image** — no rebuild. `BACKEND` and `PORT` together are what `/api` is proxied to,so they have to name a service the web container can actually reach on your compose network.@@ -366,6 +376,9 @@ everybody registers again — which is why it pays to settle the domain before o| Day reminder fires at the wrong time | Toggle it off and on in Settings so it re-detects your browser's timezone (also happens automatically on every app load — see section 7). || Notifications switch is off although I turned it on | The server no longer holds the subscription (rebuilt `data/db.json`, regenerated `vapid.json`); the app re-registers on the next start, or switch it on again. On iOS, push only works from the Home Screen icon. || Want to reset a stuck login | Delete the cookie in your browser; sessions are just signed cookies. |+| The app says "Your server no longer accepts this phone" (or "this browser") | The server answered 401. Usual causes: "sign out everywhere" was used, the account was disabled, `data/secret` was lost or replaced when the stack was moved (every session and pairing dies with it), or a proxy with its own login rejects requests that carry `Authorization: Bearer`. Nothing on the device is lost: pair the phone again (browser: Settings → "Pair the mobile app"), or sign in again in the browser, and what the device kept is merged into the account. |+| The app says the server "answered with something other than openGym (HTTP 200)" | Something other than the API answered `/api/*` with a success page — an auth proxy's sign-in page, or a catch-all route serving `index.html`. Every API answer is JSON; forward `/api/*` to the API unchanged. |+| The app says "Your server answered with an error (HTTP …)" | The code is what the server or its proxy sent: 502/504 usually means the API container is down or unreachable from `web`, 413 that the proxy's upload limit is too small. Changes stay on the device and go through once the server answers. || `docker compose pull` fails with "denied" / "unauthorized" | The prebuilt images aren't published yet, or need to be, or the GHCR package is still private — build from source instead (`docker compose up -d --build`). || Exercise images/GIFs blank when a routine is open | Fixed in current images (issue #79). On an older build, see the note below. |