Repository navigation
Description
Problem
Two-factor actions show Better Auth's own English refusal when the page is out of date. With Settings › Account open in two tabs:
- Choose Disable in tab A to turn two-factor authentication off.
- In tab B, which still shows it on, choose Regenerate backup codes and confirm the password.
Tab B's password dialog then shows "Two factor isn't enabled" in English, in every UI language. The section keeps claiming two-factor is on, and nothing tells the person to reload.
The forced enrollment page /2fa-enroll has the same gap. Enroll in one tab, then submit the password in a second enrollment tab, and the second tab shows "TOTP is already enabled" instead of moving on.
Cause
All paths below are at main d08251809 (better-auth 1.7.5).
-
Raw-message fallback:
services/platform/app/features/settings/account/components/two-factor-section.tsx:238, and also lines 84 and 209, setresult.error?.message ?? t(...)for any refusal thatreadPasswordRefusaldoesn't classify. That classifier recognizes onlyINVALID_PASSWORDand 429.services/platform/app/routes/2fa-enroll.tsx:113does the same. -
Better Auth's refusals are fixed English strings:
generate-backup-codeschecksuser.twoFactorEnabledfirst and refuses withTWO_FACTOR_NOT_ENABLED("Two factor isn't enabled",dist/plugins/two-factor/backup-codes/index.mjs:278);enablerefuses a verified TOTP withTOTP_ALREADY_ENABLED("TOTP is already enabled",dist/plugins/two-factor/index.mjs:132).
-
Why the other tab goes stale:
- the status read
twoFactorStatusQuery(app/lib/backend/account.ts:86-93) keeps the defaultstaleTimeof 5 minutes; router.tsxrefetches on window focus only after an error;backend/auth/auth.tsemits realtime hints only for teams and API keys, not for two-factor changes.
So the other tab keeps showing the old state for up to 5 minutes.
- the status read
Expected
- Map the two codes:
TWO_FACTOR_NOT_ENABLEDandTOTP_ALREADY_ENABLEDget localized sentences that name the cause, such as "Two-factor authentication was turned off in another window."- The section invalidates
twoFactorStatusQuery, so the page shows the real state. - On the enrollment page,
TOTP_ALREADY_ENABLEDcontinues to the next step instead of showing an error.
- No raw fallback: never show
result.error.message. Fall back to the localizederrors.*Failedtexts. - Optionally: emit a
me/account hint on two-factor changes, so other tabs refresh.
Regression: component tests where generateBackupCodes answers 400 TWO_FACTOR_NOT_ENABLED and enable answers 400 TOTP_ALREADY_ENABLED. Each must show the localized text in de and fr, never the English server message, and refresh the status read.
Severity and owner
- Severity: low. It needs a second tab within 5 minutes, and no data is lost. It's on critical surfaces (
settings.account,auth.two-factor). - Owner: platform (auth and account).
- Related: bug(i18n): French uses two names for two-factor authentication across the UI and guides #4350 (French two-factor terms) and bug(platform): the Language menu marks a language selected while its catalog is still loading or failed, and re-picking it never retries #4421 (language menu).
- Found by: Review A (TALE-358), 2026-10-11 04:15 Zurich occurrence, by static reading of the app and the published better-auth 1.7.5 package. Not observed live, because the stack is blocked by the missing reservation.
Activity
fix(platform): say when another tab turned two-factor on or off
fix(platform): say when another tab turned two-factor on or off