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
Settings: the sign-in e-mail row needs a password, and the address check is the server's
Duarte Santos98177a30fe2f
diff --git a/frontend/src/components/PasswordAuth.jsx b/frontend/src/components/PasswordAuth.jsxindex 7498dab72..2932e85bc 100644--- a/frontend/src/components/PasswordAuth.jsx+++ b/frontend/src/components/PasswordAuth.jsx@@ -20,9 +20,16 @@ import { Row, Button } from './ui.jsx'// answered without a round trip. The server still decides.export const MIN_PASSWORD = 10export const passwordOn = config => !!config?.password_login-// The loosest look at an address that still catches a name typed in the wrong field; the server-// (normalizeEmail in api/password.js) decides.-export const looksLikeEmail = s => s.length <= 254 && /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(s)+// An address the way the server stores and compares it (nameKey in api/password.js): NFKC,+// trimmed, lower-cased.+export const foldEmail = s => String(s || '').normalize('NFKC').trim().toLowerCase()+// The server's own check (normalizeEmail and EMAIL_RE in api/password.js), so what passes here is+// what the server takes; a test holds the two together. The server still decides.+const EMAIL_RE = /^[^\s@<>()[\]\\,;:"]{1,64}@(?=.{1,253}$)[^\s@<>()[\]\\,;:"._-][^\s@<>()[\]\\,;:"]*\.[^\s@<>()[\]\\,;:".]{2,}$/u+export const looksLikeEmail = s => {+ const e = foldEmail(s)+ return !!e && [...e].length <= 254 && EMAIL_RE.test(e) && !e.includes('..')+}const ui = () => useUI.getState()const toast = m => ui().toast(m)@@ -317,7 +324,9 @@ export function PasswordRow({ version = 0 }) {return <><Row icon="key" iconTint="var(--orange)" title={t('Password')} subtitle={subtitle} accessory={blocked ? 'none' : 'chevron'}onClick={blocked ? undefined : () => ui().openSheet(close => <PasswordSheet status={st} close={close} done={load} />)} />- <EmailRow status={st} done={load} />+ {/* The server only signs in by an address that belongs to a profile with a password, so+ without one the row is left out; one already saved stays reachable to change or remove. */}+ {(st.set || st.email) && <EmailRow status={st} done={load} />}</>}@@ -407,7 +416,8 @@ function RemovePasswordSheet({ status, close, done }) {the proof a password does (ProveOwner): a copied session must not choose how the owner signsin. `status` is GET /api/account/password, whose `email` only the owner ever gets. */export function EmailRow({ status, done }) {- const subtitle = status.email ? t('Sign in with “{0}” instead of your name', status.email)+ const subtitle = status.email && !status.set ? t('“{0}” is saved, but signs in only once this profile has a password.', status.email)+ : status.email ? t('Sign in with “{0}” instead of your name', status.email): t('Not set — sign in with an e-mail instead of your name.')return <Row icon="envelope" iconTint="var(--blue)" title={t('Sign-in e-mail')} subtitle={subtitle} accessory="chevron"onClick={() => ui().openSheet(close => <EmailSheet status={status} close={close} done={done} />)} />@@ -424,7 +434,7 @@ export function EmailSheet({ status, close, done }) {const next = ev => {ev.preventDefault()const bad = !clean || !looksLikeEmail(clean) ? t('That is not an e-mail address.')- : clean.toLowerCase() === status.email ? t('That is already your sign-in e-mail.')+ : foldEmail(clean) === status.email ? t('That is already your sign-in e-mail.'): nullif (bad) { setErr(bad); return }setErr(null); setStep('confirm')diff --git a/frontend/src/components/PasswordAuth.test.jsx b/frontend/src/components/PasswordAuth.test.jsxindex a7f8c21e6..11c49fd87 100644--- a/frontend/src/components/PasswordAuth.test.jsx+++ b/frontend/src/components/PasswordAuth.test.jsx@@ -2,7 +2,8 @@import React, { act } from 'react'import { createRoot } from 'react-dom/client'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { passwordError, PasswordSignInSheet, PasswordRegisterForm, PasswordRow, PasswordSheet, EmailSheet } from './PasswordAuth.jsx'+import { passwordError, PasswordSignInSheet, PasswordRegisterForm, PasswordRow, PasswordSheet, EmailSheet, looksLikeEmail } from './PasswordAuth.jsx'+import { normalizeEmail } from '../../../api/password.js'globalThis.IS_REACT_ACT_ENVIRONMENT = true@@ -298,6 +299,27 @@ describe('Settings → Password', () => {expect(sheet.querySelector('h3').textContent).toBe('Add a sign-in e-mail')})+ // The server signs in by an address only for a profile with a password (emailHolder in+ // api/server.js), so a passkey-only profile, or one whose name is blocked, is not offered one;+ // an address saved while a password existed stays reachable, and says it is asleep.+ it('the sign-in e-mail row needs a password, and a saved address without one says it does not sign in', async () => {+ const titles = host => [...host.querySelectorAll('.lrow-t')].map(e => e.textContent)+ const subs = host => [...host.querySelectorAll('.lrow-s')].map(e => e.textContent)+ mocks.answers['GET /api/account/password'] = { set: false, setAt: null, passkeys: 1, name: 'Ana', nameTaken: false, email: null }+ const passkeyOnly = mount(<PasswordRow />)+ await settle()+ expect(titles(passkeyOnly)).toEqual(['Password'])+ mocks.answers['GET /api/account/password'] = { set: false, setAt: null, passkeys: 1, name: 'Ana', nameTaken: true, email: null }+ const blocked = mount(<PasswordRow />)+ await settle()+ expect(titles(blocked)).toEqual(['Password'])+ mocks.answers['GET /api/account/password'] = { set: false, setAt: null, passkeys: 1, name: 'Ana', nameTaken: false, email: '[email protected]' }+ const kept = mount(<PasswordRow />)+ await settle()+ expect(titles(kept)).toEqual(['Password', 'Sign-in e-mail'])+ expect(subs(kept)[1]).toBe('“[email protected]” is saved, but signs in only once this profile has a password.')+ })+it('a first password is confirmed with the passkey and sent with its assertion', async () => {const done = vi.fn(), close = vi.fn()const host = mount(<PasswordSheet status={{ set: false, passkeys: 1, name: 'Ana' }} close={close} done={done} />)@@ -493,6 +515,22 @@ describe('Settings → Sign-in e-mail', () => {expect(alertText(host)).toBe('That is already your sign-in e-mail.')})+ it('the address it already has is recognised the way the server folds it (NFKC), not only by case', async () => {+ const { host } = open({ set: true, passkeys: 1, name: 'Ana', email: '[email protected]' })+ type(byPlaceholder(host, 'E-mail address'), '\[email protected]') // a full-width "A"+ await submit(host)+ expect(alertText(host)).toBe('That is already your sign-in e-mail.')+ expect(posts()).toEqual([])+ })++ it('looks at an address the way the server does, so nothing it accepts is refused here or the other way round', () => {+ const cases = ['[email protected]', ' [email protected] ', '\[email protected]', '[email protected]', '[email protected]', 'ana@example',+ 'ana@@example.com', 'a [email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]',+ '"ana"@example.com', 'ana@exa,mple.com', '[email protected]', 'x'.repeat(65) + '@example.com', 'a@' + 'b'.repeat(250) + '.com',+ 'ana@exämple.de', '[email protected].', '', '@example.com', 'ana@']+ for (const c of cases) expect(looksLikeEmail(c), JSON.stringify(c)).toBe(normalizeEmail(c) !== null)+ })+it('removing asks for the same proof, then removes', async () => {mocks.answers['DELETE /api/account/email'] = { ok: true, email: null }const { host, close, done } = open({ set: true, passkeys: 1, name: 'Ana', email: '[email protected]' })diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 3ba4e1ebc..7c2464400 100644--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@ -63,7 +63,7 @@ describe('Brazilian Portuguese locale', () => {// The sign-in e-mail's strings are overridden, not inherited: pt-PT says palavra-passe and «».expect(ptBR['Wrong name, e-mail or password.']).toBe('Nome, e-mail ou senha incorretos.')expect(ptBR['Sign-in e-mail']).toBe('E-mail de login')- for (const key of ['Name or e-mail', 'Sign in with “{0}” instead of your name', 'Type it at “Sign in with password” instead of your profile name. Nothing is ever sent to it — a forgotten password is still reset by your admin.'])+ for (const key of ['Name or e-mail', 'Sign in with “{0}” instead of your name', '“{0}” is saved, but signs in only once this profile has a password.', 'Type it at “Sign in with password” instead of your profile name. Nothing is ever sent to it — a forgotten password is still reset by your admin.'])expect(key in PT_BR_OVERRIDES, key).toBe(true)})})diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex cab2a0a0f..8904eced3 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -1551,6 +1551,7 @@ export default {'Another profile already uses this e-mail address.': 'هناك ملف شخصي آخر يستخدم عنوان البريد الإلكتروني هذا.','Sign-in e-mail': 'بريد تسجيل الدخول','Sign in with “{0}” instead of your name': 'سجّل الدخول بـ «{0}» بدلًا من اسمك',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» محفوظ، لكنه لا يُستخدم لتسجيل الدخول إلا بعد أن يصبح لهذا الملف كلمة مرور.','Not set — sign in with an e-mail instead of your name.': 'غير معيّن — سجّل الدخول ببريد إلكتروني بدلًا من اسمك.','Change sign-in e-mail': 'تغيير بريد تسجيل الدخول','Add a sign-in e-mail': 'إضافة بريد لتسجيل الدخول',diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 00a225f6d..d0467cf21 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -349,6 +349,7 @@ export default {'Another profile already uses this e-mail address.': 'Ein anderes Profil verwendet diese E-Mail-Adresse schon.','Sign-in e-mail': 'Anmelde-E-Mail','Sign in with “{0}” instead of your name': 'Mit „{0}“ statt deinem Namen anmelden',+ '“{0}” is saved, but signs in only once this profile has a password.': '„{0}“ ist gespeichert, meldet dich aber erst an, wenn dieses Profil ein Passwort hat.','Not set — sign in with an e-mail instead of your name.': 'Nicht festgelegt – melde dich mit einer E-Mail statt deinem Namen an.','Change sign-in e-mail': 'Anmelde-E-Mail ändern','Add a sign-in e-mail': 'Anmelde-E-Mail hinzufügen',diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex f8a8f0c8f..62657166c 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Otro perfil ya usa esta dirección de correo.','Sign-in e-mail': 'Correo de inicio de sesión','Sign in with “{0}” instead of your name': 'Inicia sesión con «{0}» en lugar de tu nombre',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» está guardado, pero solo sirve para iniciar sesión cuando este perfil tenga contraseña.','Not set — sign in with an e-mail instead of your name.': 'Sin configurar — inicia sesión con un correo en lugar de tu nombre.','Change sign-in e-mail': 'Cambiar correo de inicio de sesión','Add a sign-in e-mail': 'Añadir un correo de inicio de sesión',diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex fc3937a45..4eb48f9f4 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Un autre profil utilise déjà cette adresse e-mail.','Sign-in e-mail': 'E-mail de connexion','Sign in with “{0}” instead of your name': 'Connecte-toi avec « {0} » au lieu de ton nom',+ '“{0}” is saved, but signs in only once this profile has a password.': '« {0} » est enregistré, mais ne sert à te connecter qu’une fois que ce profil a un mot de passe.','Not set — sign in with an e-mail instead of your name.': 'Non défini — connecte-toi avec un e-mail au lieu de ton nom.','Change sign-in e-mail': 'Modifier l’e-mail de connexion','Add a sign-in e-mail': 'Ajouter un e-mail de connexion',diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 001a10577..096f823c5 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'कोई दूसरी प्रोफ़ाइल पहले से यह ईमेल पता इस्तेमाल करती है।','Sign-in e-mail': 'साइन-इन ईमेल','Sign in with “{0}” instead of your name': 'अपने नाम की जगह "{0}" से साइन इन करें',+ '“{0}” is saved, but signs in only once this profile has a password.': '"{0}" सेव है, लेकिन इससे साइन इन तभी होगा जब इस प्रोफ़ाइल का पासवर्ड हो।','Not set — sign in with an e-mail instead of your name.': 'सेट नहीं है — अपने नाम की जगह ईमेल से साइन इन करें।','Change sign-in e-mail': 'साइन-इन ईमेल बदलें','Add a sign-in e-mail': 'साइन-इन ईमेल जोड़ें',diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex e7c29e50b..ae98bebf0 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -341,6 +341,7 @@ export default {'Another profile already uses this e-mail address.': 'Egy másik profil már használja ezt az e-mail-címet.','Sign-in e-mail': 'Bejelentkezési e-mail','Sign in with “{0}” instead of your name': 'Bejelentkezés „{0}” címmel a neved helyett',+ '“{0}” is saved, but signs in only once this profile has a password.': '„{0}” el van mentve, de csak akkor lehet vele bejelentkezni, ha ennek a profilnak van jelszava.','Not set — sign in with an e-mail instead of your name.': 'Nincs beállítva — jelentkezz be e-maillel a neved helyett.','Change sign-in e-mail': 'Bejelentkezési e-mail módosítása','Add a sign-in e-mail': 'Bejelentkezési e-mail hozzáadása',diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 9ddda66ab..bca26f0ed 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Un altro profilo usa già questo indirizzo e-mail.','Sign-in e-mail': 'E-mail di accesso','Sign in with “{0}” instead of your name': 'Accedi con «{0}» invece che con il tuo nome',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» è salvato, ma serve per accedere solo quando questo profilo avrà una password.','Not set — sign in with an e-mail instead of your name.': 'Non impostata — accedi con un’e-mail invece che con il tuo nome.','Change sign-in e-mail': 'Cambia e-mail di accesso','Add a sign-in e-mail': 'Aggiungi un’e-mail di accesso',diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex b02d1a57b..c19bba0ec 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': '다른 프로필이 이미 이 이메일 주소를 사용합니다.','Sign-in e-mail': '로그인 이메일','Sign in with “{0}” instead of your name': '이름 대신 "{0}"(으)로 로그인',+ '“{0}” is saved, but signs in only once this profile has a password.': '"{0}"이(가) 저장되어 있지만, 이 프로필에 비밀번호가 있어야 로그인에 쓸 수 있어요.','Not set — sign in with an e-mail instead of your name.': '설정 안 됨 — 이름 대신 이메일로 로그인하세요.','Change sign-in e-mail': '로그인 이메일 변경','Add a sign-in e-mail': '로그인 이메일 추가',diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex 8a26609a5..13578d622 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Inny profil używa już tego adresu e-mail.','Sign-in e-mail': 'E-mail do logowania','Sign in with “{0}” instead of your name': 'Loguj się „{0}” zamiast nazwą',+ '“{0}” is saved, but signs in only once this profile has a password.': '„{0}” jest zapisany, ale posłuży do logowania dopiero, gdy ten profil będzie mieć hasło.','Not set — sign in with an e-mail instead of your name.': 'Nie ustawiono — loguj się e-mailem zamiast nazwą.','Change sign-in e-mail': 'Zmień e-mail do logowania','Add a sign-in e-mail': 'Dodaj e-mail do logowania',diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex f671b341a..e905161aa 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -344,6 +344,7 @@ export const PT_BR_OVERRIDES = {'Another profile already uses this e-mail address.': 'Outro perfil já usa este endereço de e-mail.','Sign-in e-mail': 'E-mail de login','Sign in with “{0}” instead of your name': 'Entre com “{0}” em vez do seu nome',+ '“{0}” is saved, but signs in only once this profile has a password.': '“{0}” está salvo, mas só serve para entrar depois que este perfil tiver uma senha.','Not set — sign in with an e-mail instead of your name.': 'Não definido — entre com um e-mail em vez do seu nome.','Change sign-in e-mail': 'Alterar e-mail de login','Add a sign-in e-mail': 'Adicionar um e-mail de login',diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex d78d39e45..ec308021e 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Outro perfil já usa este endereço de e-mail.','Sign-in e-mail': 'E-mail de início de sessão','Sign in with “{0}” instead of your name': 'Inicia sessão com «{0}» em vez do teu nome',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» está guardado, mas só serve para iniciar sessão quando este perfil tiver uma palavra-passe.','Not set — sign in with an e-mail instead of your name.': 'Não definido — inicia sessão com um e-mail em vez do teu nome.','Change sign-in e-mail': 'Alterar e-mail de início de sessão','Add a sign-in e-mail': 'Adicionar um e-mail de início de sessão',diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 7c49aca07..d9283369c 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Другой профиль уже использует этот адрес e-mail.','Sign-in e-mail': 'E-mail для входа','Sign in with “{0}” instead of your name': 'Входи с «{0}» вместо имени',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» сохранён, но для входа сработает, только когда у этого профиля будет пароль.','Not set — sign in with an e-mail instead of your name.': 'Не задан — входи с e-mail вместо имени.','Change sign-in e-mail': 'Изменить e-mail для входа','Add a sign-in e-mail': 'Добавить e-mail для входа',diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 77f56310b..fe2847a2a 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -341,6 +341,7 @@ export default {'Another profile already uses this e-mail address.': 'มีโปรไฟล์อื่นใช้ที่อยู่อีเมลนี้อยู่แล้ว','Sign-in e-mail': 'อีเมลสำหรับเข้าสู่ระบบ','Sign in with “{0}” instead of your name': 'เข้าสู่ระบบด้วย “{0}” แทนชื่อของคุณ',+ '“{0}” is saved, but signs in only once this profile has a password.': 'บันทึก “{0}” ไว้แล้ว แต่จะใช้เข้าสู่ระบบได้เมื่อโปรไฟล์นี้มีรหัสผ่านเท่านั้น','Not set — sign in with an e-mail instead of your name.': 'ยังไม่ได้ตั้ง — เข้าสู่ระบบด้วยอีเมลแทนชื่อของคุณ','Change sign-in e-mail': 'เปลี่ยนอีเมลสำหรับเข้าสู่ระบบ','Add a sign-in e-mail': 'เพิ่มอีเมลสำหรับเข้าสู่ระบบ',diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 830550870..166252e8a 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': 'Başka bir profil bu e-posta adresini zaten kullanıyor.','Sign-in e-mail': 'Giriş e-postası','Sign in with “{0}” instead of your name': 'İsmin yerine “{0}” ile giriş yap',+ '“{0}” is saved, but signs in only once this profile has a password.': '“{0}” kayıtlı, ancak bu profilin bir şifresi olduğunda giriş için kullanılabilir.','Not set — sign in with an e-mail instead of your name.': 'Belirlenmedi — ismin yerine bir e-postayla giriş yap.','Change sign-in e-mail': 'Giriş e-postasını değiştir','Add a sign-in e-mail': 'Giriş e-postası ekle',diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex c94bb2db0..5f9a91768 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -1495,6 +1495,7 @@ export default {'Another profile already uses this e-mail address.': 'Інший профіль уже використовує цю адресу e-mail.','Sign-in e-mail': 'E-mail для входу','Sign in with “{0}” instead of your name': 'Входь з «{0}» замість імені',+ '“{0}” is saved, but signs in only once this profile has a password.': '«{0}» збережено, але для входу спрацює, лише коли в цього профілю буде пароль.','Not set — sign in with an e-mail instead of your name.': 'Не задано — входь з e-mail замість імені.','Change sign-in e-mail': 'Змінити e-mail для входу','Add a sign-in e-mail': 'Додати e-mail для входу',diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 5db072187..222a04d9f 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -335,6 +335,7 @@ export default {'Another profile already uses this e-mail address.': '已有另一个档案在使用这个邮箱地址。','Sign-in e-mail': '登录邮箱','Sign in with “{0}” instead of your name': '用“{0}”代替名字登录',+ '“{0}” is saved, but signs in only once this profile has a password.': '“{0}”已保存,但只有此个人资料设置了密码后才能用它登录。','Not set — sign in with an e-mail instead of your name.': '未设置 — 用邮箱代替名字登录。','Change sign-in e-mail': '更改登录邮箱','Add a sign-in e-mail': '添加登录邮箱',