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
Pairing: a wrong or expired code says so in the app's language
Duarte Santosf41754332e46
diff --git a/api/openapi.yaml b/api/openapi.yamlindex c58381890..d37bd13fd 100644--- a/api/openapi.yaml+++ b/api/openapi.yaml@@ -605,7 +605,7 @@ paths:content:application/json:schema: { $ref: '#/components/schemas/Error' }- example: { error: "invalid or expired code" }+ example: { error: "invalid or expired code", code: "pair-invalid" }/api/login/password:post:diff --git a/api/server.js b/api/server.jsindex 376863ca1..e67f93d9b 100644--- a/api/server.js+++ b/api/server.js@@ -1992,12 +1992,12 @@ const routes = {if (p) pairings.delete(code);if (!p || p.exp < Date.now()) {audit(req, 'auth.pair.fail', { ok: false, msg: 'code-invalid' });- return json(res, 400, { error: 'invalid or expired code' });+ return json(res, 400, { error: 'invalid or expired code', code: 'pair-invalid' });}const user = db.users.find(u => u.id === p.uid);if (!user || user.disabled) {audit(req, 'auth.pair.fail', { ok: false, uid: p.uid, msg: 'user-unavailable' });- return json(res, 400, { error: 'invalid or expired code' });+ return json(res, 400, { error: 'invalid or expired code', code: 'pair-invalid' });}audit(req, 'auth.pair.ok', { user });json(res, 200, { token: makeSession(user), user: { id: user.id, name: user.name, admin: isAdmin(user) } });diff --git a/api/test/server-pairing.test.js b/api/test/server-pairing.test.jsindex c69f9d1e3..cd8d909d1 100644--- a/api/test/server-pairing.test.js+++ b/api/test/server-pairing.test.js@@ -65,7 +65,7 @@ test('logout/all invalidates the account\'s outstanding pairing codes and nobodyassert.equal((await post('/api/logout/all', cookie('u_test_1', 0))).status, 200);const r = await redeem(stale);assert.equal(r.status, 400);- assert.deepEqual(await r.json(), { error: 'invalid or expired code' });+ assert.deepEqual(await r.json(), { error: 'invalid or expired code', code: 'pair-invalid' });// the other account's code is untouchedassert.equal((await redeem(other)).status, 200);diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.jsindex 7537cc660..ac44849e7 100644--- a/frontend/src/lib/api.js+++ b/frontend/src/lib/api.js@@ -297,6 +297,9 @@ export async function pairRedeem(serverBase, code, { probeMs = PROBE_MS } = {})method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code })}, TIMEOUT_GET_MS)} catch (e) {+ // A wrong, spent or expired code is the one refusal a person can fix, and the server says it+ // in English only ('invalid or expired code'), so it is said here in the UI language.+ if (e && e.status === 400) throw failure(t('That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.'), 'pair-invalid', 400)// The server answered (any status) or did not answer in time: that error says it already.if (e && (e.status != null || e.code)) throw eif (await blockedAsMixedContent(serverBase)) {diff --git a/frontend/src/lib/api.pair-probe.test.js b/frontend/src/lib/api.pair-probe.test.jsindex 5fb46d08b..bcfbb8b21 100644--- a/frontend/src/lib/api.pair-probe.test.js+++ b/frontend/src/lib/api.pair-probe.test.js@@ -82,10 +82,17 @@ describe('pairRedeem when the request never gets an answer', () => {expect(e.code).toBe('unreachable')})- it('an answer from the server is passed on as it is, with no probe', async () => {- const fetch = vi.fn(async () => new Response(JSON.stringify({ error: 'invalid or expired code' }), { status: 400, headers: { 'content-type': 'application/json' } }))+ it('a refused code is said in words a person can act on, with no probe', async () => {+ const fetch = vi.fn(async () => new Response(JSON.stringify({ error: 'invalid or expired code', code: 'pair-invalid' }), { status: 400, headers: { 'content-type': 'application/json' } }))vi.stubGlobal('fetch', fetch)- await expect(pairRedeem('https://gym.example.com', 'ABCD2345')).rejects.toMatchObject({ status: 400, message: 'invalid or expired code' })+ await expect(pairRedeem('https://gym.example.com', 'ABCD2345')).rejects.toMatchObject({ status: 400, code: 'pair-invalid', message: 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.' })+ expect(fetch).toHaveBeenCalledTimes(1)+ })++ it('any other answer from the server is passed on as it is, with no probe', async () => {+ const fetch = vi.fn(async () => new Response(JSON.stringify({ error: 'the server is busy, try again in a moment', code: 'busy' }), { status: 503, headers: { 'content-type': 'application/json' } }))+ vi.stubGlobal('fetch', fetch)+ await expect(pairRedeem('https://gym.example.com', 'ABCD2345')).rejects.toMatchObject({ status: 503, message: 'the server is busy, try again in a moment' })expect(fetch).toHaveBeenCalledTimes(1)})diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex be1fa9230..33fc67749 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -1954,4 +1954,5 @@ export default {'Couldn’t read that file.': 'تعذّرت قراءة هذا الملف.','This server doesn’t know that passkey. Make a profile first.': 'هذا الخادم لا يعرف مفتاح المرور هذا. أنشئ ملفًا شخصيًا أولًا.','That took a little too long. Give it another go.': 'استغرق ذلك وقتًا أطول قليلًا من اللازم. جرّب مرة أخرى.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'لم ينجح هذا الرمز. الرموز صالحة لمدة 5 دقائق ولمرة واحدة فقط، فاطلب رمزًا جديدًا.',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 945d8f0b0..ae1b6b0b6 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1921,4 +1921,5 @@ export default {'Couldn’t read that file.': 'Diese Datei lässt sich nicht lesen.','This server doesn’t know that passkey. Make a profile first.': 'Diesen Passkey kennt der Server nicht. Erstell zuerst ein Profil.','That took a little too long. Give it another go.': 'Das hat etwas zu lange gedauert. Versuch es gleich noch mal.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Der Code hat nicht geklappt. Codes gelten 5 Minuten und nur einmal, also hol dir einen frischen.',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 5548441b3..1c5b7f9d5 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'No se pudo leer ese archivo.','This server doesn’t know that passkey. Make a profile first.': 'Este servidor no conoce esa passkey. Crea un perfil primero.','That took a little too long. Give it another go.': 'Eso tardó un poco de más. Inténtalo otra vez.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Ese código no funcionó. Los códigos duran 5 minutos y sirven una sola vez, así que pide uno nuevo.',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex f9f7c4bb8..441b95301 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'Impossible de lire ce fichier.','This server doesn’t know that passkey. Make a profile first.': 'Ce serveur ne connaît pas cette passkey. Crée d’abord un profil.','That took a little too long. Give it another go.': 'C’était un peu trop long. Réessaie.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Ce code n’a pas marché. Un code dure 5 minutes et ne sert qu’une fois, alors prends-en un tout neuf.',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 816c701cf..b93597262 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'यह फ़ाइल पढ़ी नहीं जा सकी।','This server doesn’t know that passkey. Make a profile first.': 'यह सर्वर इस पासकी को नहीं पहचानता। पहले एक प्रोफ़ाइल बनाएँ।','That took a little too long. Give it another go.': 'इसमें थोड़ा ज़्यादा समय लग गया। एक बार फिर कोशिश करें।',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'यह कोड काम नहीं किया। कोड 5 मिनट चलते हैं और सिर्फ़ एक बार काम करते हैं, तो एक नया कोड ले लें।',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex a60013a59..b0417c8c6 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -1904,4 +1904,5 @@ export default {'Couldn’t read that file.': 'Ezt a fájlt nem sikerült beolvasni.','This server doesn’t know that passkey. Make a profile first.': 'Ez a szerver nem ismeri ezt a jelszókulcsot. Előbb hozz létre egy profilt.','That took a little too long. Give it another go.': 'Ez egy kicsit túl sokáig tartott. Próbáld újra.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Ez a kód nem működött. A kódok 5 percig érvényesek és csak egyszer használhatók, úgyhogy kérj egy újat.',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 679695e9f..1d93ffa07 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'Impossibile leggere questo file.','This server doesn’t know that passkey. Make a profile first.': 'Questo server non conosce questa passkey. Crea prima un profilo.','That took a little too long. Give it another go.': 'Ci è voluto un po’ troppo. Riprova.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Questo codice non ha funzionato. I codici durano 5 minuti e valgono una volta sola, quindi prendine uno nuovo.',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 050ae0692..7c16dee66 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': '이 파일을 읽을 수 없어요.','This server doesn’t know that passkey. Make a profile first.': '이 서버는 이 패스키를 몰라요. 먼저 프로필을 만들어 주세요.','That took a little too long. Give it another go.': '조금 너무 오래 걸렸어요. 다시 해 보세요.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': '이 코드는 안 됐어요. 코드는 5분 동안 한 번만 쓸 수 있으니 새 코드를 받아 주세요.',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex a36c60eea..067154ff1 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'Nie udało się odczytać tego pliku.','This server doesn’t know that passkey. Make a profile first.': 'Ten serwer nie zna tego passkey. Najpierw utwórz profil.','That took a little too long. Give it another go.': 'Trwało to trochę za długo. Spróbuj jeszcze raz.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Ten kod nie zadziałał. Kody są ważne 5 minut i działają raz, więc weź świeży.',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex 8b7736754..7541d3702 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1180,6 +1180,7 @@ export const PT_BR_OVERRIDES = {'Couldn’t read that file.': 'Não foi possível ler esse arquivo.','This server doesn’t know that passkey. Make a profile first.': 'Este servidor não conhece essa chave de acesso. Crie um perfil primeiro.','That took a little too long. Give it another go.': 'Demorou um pouquinho demais. Tente de novo.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Esse código não funcionou. Os códigos duram 5 minutos e só valem uma vez, então pegue um novo.',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex d6e7b14fc..a9fb4c9ac 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'Não foi possível ler esse ficheiro.','This server doesn’t know that passkey. Make a profile first.': 'Este servidor não conhece essa passkey. Cria primeiro um perfil.','That took a little too long. Give it another go.': 'Demorou um bocadinho demais. Tenta outra vez.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Esse código não funcionou. Os códigos duram 5 minutos e só servem uma vez, por isso pede um novo.',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex da02075a8..c16ff3097 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1905,4 +1905,5 @@ export default {'Couldn’t read that file.': 'Не удалось прочитать этот файл.','This server doesn’t know that passkey. Make a profile first.': 'Этот сервер не знает такой ключ доступа. Сначала создайте профиль.','That took a little too long. Give it another go.': 'Это заняло слишком много времени. Попробуйте ещё раз.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Этот код не сработал. Коды действуют 5 минут и только один раз, так что возьмите свежий.',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 749728f10..0d8053273 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -1912,4 +1912,5 @@ export default {'Couldn’t read that file.': 'อ่านไฟล์นี้ไม่ได้','This server doesn’t know that passkey. Make a profile first.': 'เซิร์ฟเวอร์นี้ไม่รู้จักพาสคีย์นี้ สร้างโปรไฟล์ก่อนนะ','That took a little too long. Give it another go.': 'ใช้เวลานานไปหน่อย ลองอีกครั้งนะ',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'รหัสนี้ใช้ไม่ได้ รหัสใช้ได้ 5 นาทีและใช้ได้ครั้งเดียว ขอรหัสใหม่นะ',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 092c1bf2c..00f1f55d6 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': 'Bu dosya okunamadı.','This server doesn’t know that passkey. Make a profile first.': 'Bu sunucu o geçiş anahtarını tanımıyor. Önce bir profil oluştur.','That took a little too long. Give it another go.': 'Bu biraz fazla uzun sürdü. Bir kez daha dene.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Bu kod işe yaramadı. Kodlar 5 dakika geçerli ve tek kullanımlık, yenisini al.',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex d7ec9c903..473d31761 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -1898,4 +1898,5 @@ export default {'Couldn’t read that file.': 'Не вдалося прочитати цей файл.','This server doesn’t know that passkey. Make a profile first.': 'Цей сервер не знає такого ключа доступу. Спершу створіть профіль.','That took a little too long. Give it another go.': 'Це тривало трохи задовго. Спробуйте ще раз.',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': 'Цей код не спрацював. Коди діють 5 хвилин і лише один раз, тож візьміть свіжий.',}diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex 02a163f00..b10d4031b 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -1894,4 +1894,5 @@ export default {'Couldn’t read that file.': '無法讀取這個檔案。','This server doesn’t know that passkey. Make a profile first.': '這個伺服器不認得這個通行密鑰。請先建立個人檔案。','That took a little too long. Give it another go.': '花的時間有點太久了。再試一次吧。',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': '這個代碼沒用。代碼只在 5 分鐘內有效,而且只能用一次,換個新的吧。',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex c662e4ed8..4a8f19a09 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1901,4 +1901,5 @@ export default {'Couldn’t read that file.': '无法读取这个文件。','This server doesn’t know that passkey. Make a profile first.': '这个服务器不认识这个通行密钥。请先创建个人资料。','That took a little too long. Give it another go.': '花的时间有点太长了。再试一次吧。',+ 'That code didn’t work. Codes last 5 minutes and work once, so grab a fresh one.': '这个代码没用。代码只在 5 分钟内有效,且只能用一次,换个新的吧。',}