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
The paired phone app makes a code to sign in on a computer (#551)
Duarte Santos235450c5084b
diff --git a/frontend/src/components/Passkeys.jsx b/frontend/src/components/Passkeys.jsxindex 787cca2a2..8f40156da 100644--- a/frontend/src/components/Passkeys.jsx+++ b/frontend/src/components/Passkeys.jsx@@ -14,6 +14,7 @@ import { deviceLinkUrl, deviceLabel } from '../lib/device-link.js'import { askAddDeviceData } from '../sheets.jsx'import { passwordError, notReached, useAgainOnceReached, ProveOwner } from './PasswordAuth.jsx'import QrCanvas from './QrCanvas.jsx'+import { MOBILE } from '../lib/mobile.js'import { Row, Button } from './ui.jsx'const ui = () => useUI.getState()@@ -216,7 +217,11 @@ export function DeviceLinkSheet({ close }) {const timer = setTimeout(() => setExpired(true), Math.max(0, link.expires - Date.now()))return () => clearTimeout(timer)}, [link])- const url = link ? deviceLinkUrl(link.code) : ''+ // The phone app's own origin is not the server's (#551): the link points at the paired server.+ const server = MOBILE ? useStore.getState().sync?.server : null+ const url = link ? (server ? deviceLinkUrl(link.code, new URL(server.replace(/\/?$/, '/'))) : deviceLinkUrl(link.code)) : ''+ // A paired phone holds no passkey for the server, so there only the password can confirm.+ const passkey = !MOBILE && !!st && st.passkeys.length > 0const copy = async () => { if (await copyText(url)) toast(t('Copied')) }return <><h3>{t('Add another device')}</h3>@@ -224,8 +229,10 @@ export function DeviceLinkSheet({ close }) {<div className="muted small" style={{ marginBottom: 14 }}>{t('You get a code that lets your phone or another computer create a passkey for this profile. First confirm that it is you.')}</div>- <ProveOwner passkey={st.passkeys.length > 0} password={st.password} explain={passkeyError}- onProof={async proof => setLink(await post('/api/account/device-link', proof))} />+ {MOBILE && !st.password+ ? <div className="dim small">{t('This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.')}</div>+ : <ProveOwner passkey={passkey} password={st.password} explain={passkeyError}+ onProof={async proof => setLink(await post('/api/account/device-link', proof))} />}</> : expired ? <><div className="muted small" style={{ marginBottom: 14 }}>{t('This code has expired.')}</div><Button variant="primary" onClick={() => setLink(null)}>{t('Make a new code')}</Button>diff --git a/frontend/src/components/Passkeys.test.jsx b/frontend/src/components/Passkeys.test.jsxindex 1fcd7a7f8..1e59c1353 100644--- a/frontend/src/components/Passkeys.test.jsx+++ b/frontend/src/components/Passkeys.test.jsx@@ -11,7 +11,7 @@ globalThis.IS_REACT_ACT_ENVIRONMENT = truecode sheet with its proof, QR and expiry; and the other device's redeem sheet. The API and the passkey prompts are stand-ins; what each stepsends, and what it says back in the UI language, is the point. */const mocks = vi.hoisted(() => {- const state = { webauthn: true, sheets: [], answers: {}, calls: [], store: {} }+ const state = { webauthn: true, sheets: [], answers: {}, calls: [], store: {}, MOBILE: false }state.toast = vi.fn()state.setUser = vi.fn()state.adoptProfile = vi.fn(async () => ({}))@@ -50,6 +50,7 @@ vi.mock('../lib/api.js', () => ({passwordLogin: vi.fn(), passwordRegister: vi.fn(), passwordResetRedeem: vi.fn(),}))vi.mock('../lib/clipboard.js', () => ({ copyText: (...a) => mocks.copyText(...a) }))+vi.mock('../lib/mobile.js', () => ({ get MOBILE() { return mocks.MOBILE } }))vi.mock('../sheets.jsx', () => ({ askAddDeviceData: mocks.askAddDeviceData }))// lean-qr loads on demand; what matters here is what the QR code carries.vi.mock('./QrCanvas.jsx', () => ({ default: ({ value }) => <canvas data-qr={value} /> }))@@ -373,6 +374,32 @@ describe('Settings: a code for another device', () => {})})+// #551: the phone app paired to a server makes the code too, to sign in on a computer.+describe('a code for another device, from the paired phone app', () => {+ afterEach(() => { mocks.MOBILE = false; mocks.store = {} })+ it('confirms with the password only, and the link points at the paired server', async () => {+ mocks.MOBILE = true+ mocks.store = { sync: { server: 'https://gym.example.com' } }+ mocks.answers['GET /api/account/passkeys'] = { ...LIST, password: true }+ mocks.answers['POST /api/account/device-link'] = { code: 'K7WQ-2MZP-4HXA', expires: Date.now() + 600000 }+ const host = mount(<DeviceLinkSheet close={() => {}} />)+ await settle()+ expect(button(host, 'Confirm with a passkey')).toBeUndefined()+ type(byPlaceholder(host, 'Current password'), 'correct horse battery staple')+ await submit(host)+ expect(mocks.calls.at(-1)).toEqual({ path: '/api/account/device-link', method: 'POST', body: { current: 'correct horse battery staple' } })+ expect(host.querySelector('canvas').dataset.qr).toBe('https://gym.example.com/?link=K7WQ-2MZP-4HXA')+ })+ it('without a password says where to make it instead, and sends nothing', async () => {+ mocks.MOBILE = true+ mocks.answers['GET /api/account/passkeys'] = { ...LIST, password: false }+ const host = mount(<DeviceLinkSheet close={() => {}} />)+ await settle()+ expect(host.textContent).toContain('Make the code in a browser signed in to this profile')+ expect(mocks.calls.filter(c => c.method !== 'GET')).toEqual([])+ })+})+describe('the other device: redeeming a code', () => {const OPTIONS = { cid: 'link-cid', options: { challenge: 'xyz' }, id: 'u1', name: 'Ana' }const CAUTION = 'Only continue if this code comes from a device of your own. This browser is then signed in to “Ana”, and what you log here goes to that profile.'diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 3b7473de1..7bc80edb1 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -2391,4 +2391,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'في البطاقات والتركيز، يتخطى «السابق» و«التالي» التمرين المنتهي.','Skip completed exercises': 'تخطّي التمارين المكتملة',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'لا يستطيع هذا التطبيق التأكيد بمفتاح مرور. أنشئ الرمز في متصفح مسجّل الدخول إلى هذا الملف الشخصي، أو أضف كلمة مرور هناك أولًا.',}diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.jsindex 72fabfc14..5bb6590cc 100644--- a/frontend/src/locales/bn.js+++ b/frontend/src/locales/bn.js@@ -2415,4 +2415,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'কার্ড ও ফোকাসে আগের/পরের বোতাম শেষ হওয়া ব্যায়াম টপকে যায়।','Skip completed exercises': 'শেষ হওয়া ব্যায়াম বাদ দিন',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'এই অ্যাপ পাসকি দিয়ে নিশ্চিত করতে পারে না। এই প্রোফাইলে সাইন ইন করা ব্রাউজারে কোডটি বানান, অথবা আগে সেখানে একটি পাসওয়ার্ড যোগ করুন।',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex db03ec354..552548ea9 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -2356,4 +2356,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'In Karten und Fokus springen Zurück und Weiter über fertige Übungen.','Skip completed exercises': 'Erledigte Übungen überspringen',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Diese App kann nicht mit einem Passkey bestätigen. Erstell den Code in einem Browser, der mit diesem Profil angemeldet ist, oder leg dort zuerst ein Passwort fest.',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex b28941b5e..9b1b6b7bc 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'En Tarjetas y Enfoque, Anterior y Siguiente saltan los ejercicios terminados.','Skip completed exercises': 'Saltar ejercicios completados',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Esta app no puede confirmar con una passkey. Crea el código en un navegador con este perfil abierto, o añade allí una contraseña primero.',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 62a903a0b..fe496f4cf 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'En Cartes et Focus, Précédent et Suivant sautent les exercices terminés.','Skip completed exercises': 'Sauter les exercices terminés',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Cette app ne peut pas confirmer avec une passkey. Crée le code dans un navigateur connecté à ce profil, ou ajoute d’abord un mot de passe là-bas.',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex b700732e0..e28d8a9b4 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'कार्ड और फ़ोकस में पिछला और अगला पूरे हो चुके व्यायाम को छोड़ देते हैं।','Skip completed exercises': 'पूरे हुए व्यायाम छोड़ें',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'यह ऐप पासकी से पुष्टि नहीं कर सकता। इस प्रोफ़ाइल में साइन इन किए ब्राउज़र में कोड बनाएँ, या पहले वहाँ एक पासवर्ड जोड़ें।',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 3ec61be5e..5b5c6ba12 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -2339,4 +2339,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'Kártyák és Fókusz nézetben az Előző és a Következő átugorja a kész gyakorlatot.','Skip completed exercises': 'Kész gyakorlatok átugrása',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Ez az app nem tud jelszókulccsal megerősíteni. Készítsd el a kódot egy böngészőben, ahol ebbe a profilba vagy bejelentkezve, vagy előbb adj meg ott egy jelszót.',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex ab66cb1a3..ecfe0b39b 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'In Schede e Focus, Indietro e Avanti saltano gli esercizi finiti.','Skip completed exercises': 'Salta gli esercizi completati',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Questa app non può confermare con una passkey. Crea il codice in un browser con questo profilo, oppure aggiungi prima lì una password.',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex a5d5f0509..7ae8a9d50 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': '카드와 포커스에서 이전/다음이 끝난 운동을 건너뛰어요.','Skip completed exercises': '끝난 운동 건너뛰기',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': '이 앱에서는 패스키로 확인할 수 없어요. 이 프로필로 로그인한 브라우저에서 코드를 만들거나, 먼저 그곳에서 비밀번호를 추가하세요.',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex f0cf0f0a3..59a5ffd1f 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'W Kartach i Skupieniu przyciski Wstecz i Dalej przeskakują ukończone ćwiczenia.','Skip completed exercises': 'Pomijaj ukończone ćwiczenia',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Ta aplikacja nie może potwierdzić kluczem dostępu. Utwórz kod w przeglądarce zalogowanej na ten profil albo najpierw ustaw tam hasło.',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex d80f6bd69..460a25f51 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1475,6 +1475,8 @@ export const PT_BR_OVERRIDES = {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'Em Cartões e Foco, Anterior e Próximo pulam os exercícios concluídos.','Skip completed exercises': 'Pular exercícios concluídos',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Este aplicativo não consegue confirmar com uma chave de acesso. Crie o código em um navegador conectado a este perfil, ou adicione uma senha lá primeiro.',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex ecff150ea..d697efd21 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'Em Cartões e Foco, Anterior e Seguinte saltam os exercícios terminados.','Skip completed exercises': 'Saltar exercícios concluídos',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Esta app não consegue confirmar com uma passkey. Cria o código num navegador com este perfil, ou adiciona lá uma palavra-passe primeiro.',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex b5e6a9f01..9d0a6b7f6 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -2340,4 +2340,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'В Карточках и Фокусе «Назад» и «Далее» перескакивают готовые упражнения.','Skip completed exercises': 'Пропускать выполненные упражнения',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Это приложение не может подтвердить ключом доступа. Создайте код в браузере, где вы вошли в этот профиль, или сначала задайте там пароль.',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex f7fec030b..a3d918ae6 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -2347,4 +2347,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'ในโหมดการ์ดและโฟกัส ปุ่มก่อนหน้า/ถัดไปจะข้ามท่าที่ทำเสร็จแล้ว','Skip completed exercises': 'ข้ามท่าที่ทำเสร็จแล้ว',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'แอปนี้ยืนยันด้วยพาสคีย์ไม่ได้ สร้างรหัสในเบราว์เซอร์ที่ลงชื่อเข้าใช้โปรไฟล์นี้ หรือเพิ่มรหัสผ่านที่นั่นก่อน',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 9a58613b6..20e9505cd 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'Kartlar ve Odak düzeninde Geri ve İleri, bitmiş egzersizlerin üstünden atlar.','Skip completed exercises': 'Tamamlanan egzersizleri atla',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Bu uygulama geçiş anahtarıyla onaylayamaz. Kodu bu profille oturum açmış bir tarayıcıda oluştur ya da önce orada bir parola ekle.',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex e849ec0be..33cf41eec 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -2333,4 +2333,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': 'У Картках і Фокусі «Назад» і «Далі» перестрибують готові вправи.','Skip completed exercises': 'Пропускати виконані вправи',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': 'Цей застосунок не може підтвердити ключем доступу. Створіть код у браузері, де ви ввійшли в цей профіль, або спершу задайте там пароль.',}diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex 3031074cc..b6a6ec888 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -2329,4 +2329,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': '在卡片和專注版面中,上一個/下一個會跳過已完成的動作。','Skip completed exercises': '跳過已完成的動作',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': '此 App 無法以通行密鑰確認。請在已登入此個人檔案的瀏覽器中產生代碼,或先在那裡設定密碼。',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex f178b985f..d827d81a1 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -2336,4 +2336,6 @@ export default {// --- #523 skip completed ---'In Cards and Focus, Prev and Next hop over a finished exercise.': '在卡片和专注布局中,上一个/下一个会跳过已完成的动作。','Skip completed exercises': '跳过已完成的动作',+ // --- #551 device link from the phone ---+ 'This app can’t confirm with a passkey. Make the code in a browser signed in to this profile, or add a password there first.': '此应用无法用通行密钥确认。请在已登录此档案的浏览器中生成代码,或先在那里设置密码。',}diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsxindex 1d3a833f8..f3d1f7c61 100644--- a/frontend/src/views/Settings.jsx+++ b/frontend/src/views/Settings.jsx@@ -95,7 +95,8 @@ export default function Settings({ page = null, find = null, via = null, entryKeconst lang = effectiveLang(S, config)// This profile's passkeys and the code for another device (#95). A change to them is read back// here and by the password row, whose "Remove" depends on there being a passkey.- const passkeys = usePasskeys(!!user && !MOBILE && !DEMO && (page === 'account'))+ // On a paired phone only the code for another device uses it (#551).+ const passkeys = usePasskeys(!!user && !DEMO && (page === 'account'))const [credsV, setCredsV] = useState(0)const credsChanged = () => { passkeys.load(); setCredsV(v => v + 1) }const { update, importConflict, importBackup, setUnit, resetEverything: resetAll, setUser, pullState, pushState, resetDemo } = useStore()@@ -862,6 +863,8 @@ export default function Settings({ page = null, find = null, via = null, entryKe{user && !DEMO && <ServerSyncSection>{MOBILE && <>{user.admin && <Row icon="crown" iconTint="var(--indigo)" title={t('Admin dashboard')} accessory="chevron" onClick={() => nav('/admin')} />}+ {/* A code to sign in on a computer (#551), behind the same proof as in a browser. */}+ <DeviceLinkRow state={passkeys.st} /><AccountIdRow id={user.id} /><Row icon="signOut" iconTint="var(--red)" title={t('Disconnect')} danger onClick={disconnect} /></>}diff --git a/frontend/src/views/settings-pages.js b/frontend/src/views/settings-pages.jsindex eb34b0791..d4e8bf309 100644--- a/frontend/src/views/settings-pages.js+++ b/frontend/src/views/settings-pages.js@@ -130,7 +130,7 @@ export const SEARCH = [// Account{ page: 'account', title: 'Sync now', icon: 'reset', tint: 'var(--acc)', kw: 'server sync upload refresh status connection', when: c => !!c.user && !c.demo && c.synced },{ page: 'account', title: 'Passkeys', icon: 'fingerprint', tint: 'var(--acc)', kw: 'passkey security login', when: signedInWeb },- { page: 'account', title: 'Add another device', icon: 'qr', tint: 'var(--blue)', kw: 'device link code phone computer', when: signedInWeb },+ { page: 'account', title: 'Add another device', icon: 'qr', tint: 'var(--blue)', kw: 'device link code phone computer', when: c => !!c.user && !c.demo },{ page: 'account', title: 'Pair the mobile app', icon: 'qr', tint: 'var(--blue)', kw: 'pair phone app android iphone', when: signedInWeb },{ page: 'account', title: 'Password', icon: 'key', tint: 'var(--orange)', kw: 'password login', when: c => signedInWeb(c) && c.pwOn },{ page: 'account', title: 'Sign out', icon: 'signOut', tint: 'var(--red)', kw: 'log out logout sign out', when: signedInWeb },