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
fix: allow passkeys in Chrome on iOS
mzspicoli3e531e72e10c
diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.jsindex 6a7e6209d..a74bda0e0 100644--- a/frontend/src/lib/api.js+++ b/frontend/src/lib/api.js@@ -3,7 +3,11 @@ export const IS_APPLE = /iPhone|iPad|iPod|Macintosh/.test(navigator.userAgent)export const IS_ANDROID = /Android/.test(navigator.userAgent)export const BIO = IS_APPLE ? 'Face ID / Touch ID' : IS_ANDROID ? 'fingerprint or face unlock' : 'your fingerprint, face or PIN'export const VAULT = IS_APPLE ? 'iCloud Keychain' : IS_ANDROID ? 'Google Password Manager' : 'your password manager'-export const webauthnOK = () => !!(window.PublicKeyCredential && navigator.credentials)+// PublicKeyCredential is the WebAuthn-specific capability signal. Do not also gate the UI on+// navigator.credentials: some browsers expose WebAuthn while that generic Credential Management+// API check produces a false negative (notably Chrome on iOS). The real create/get calls still run+// only after the user chooses a passkey action and surface any genuine browser error there.+export const webauthnOK = () => typeof window.PublicKeyCredential !== 'undefined'export async function api(path, opts) {const r = await fetch(path, Object.assign({ headers: { 'Content-Type': 'application/json' } }, opts))diff --git a/frontend/src/lib/api.test.js b/frontend/src/lib/api.test.jsnew file mode 100644index 000000000..53360dcbc--- /dev/null+++ b/frontend/src/lib/api.test.js@@ -0,0 +1,35 @@+// @vitest-environment happy-dom+import { afterEach, describe, expect, it } from 'vitest'+import { webauthnOK } from './api.js'++const originalPublicKeyCredential = window.PublicKeyCredential+const originalCredentials = navigator.credentials++function setCapability(target, property, value) {+ Object.defineProperty(target, property, { configurable: true, value })+}++afterEach(() => {+ setCapability(window, 'PublicKeyCredential', originalPublicKeyCredential)+ setCapability(navigator, 'credentials', originalCredentials)+})++describe('webauthnOK', () => {+ it('accepts WebAuthn when PublicKeyCredential is exposed', () => {+ setCapability(window, 'PublicKeyCredential', class PublicKeyCredential {})+ setCapability(navigator, 'credentials', {})+ expect(webauthnOK()).toBe(true)+ })++ it('does not reject WebAuthn when the generic credentials check is unavailable', () => {+ setCapability(window, 'PublicKeyCredential', class PublicKeyCredential {})+ setCapability(navigator, 'credentials', undefined)+ expect(webauthnOK()).toBe(true)+ })++ it('rejects browsers without the WebAuthn credential type', () => {+ setCapability(window, 'PublicKeyCredential', undefined)+ setCapability(navigator, 'credentials', {})+ expect(webauthnOK()).toBe(false)+ })+})