Skip to content

bug(platform): two-factor actions show Better Auth’s English refusal in a stale tab (“Two factor isn’t enabled”, “TOTP is already enabled”) #4768

Closed

Description

@yannickmonney

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:

  1. Choose Disable in tab A to turn two-factor authentication off.
  2. 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, set result.error?.message ?? t(...) for any refusal that readPasswordRefusal doesn't classify. That classifier recognizes only INVALID_PASSWORD and 429. services/platform/app/routes/2fa-enroll.tsx:113 does the same.

  • Better Auth's refusals are fixed English strings:

    • generate-backup-codes checks user.twoFactorEnabled first and refuses with TWO_FACTOR_NOT_ENABLED ("Two factor isn't enabled", dist/plugins/two-factor/backup-codes/index.mjs:278);
    • enable refuses a verified TOTP with TOTP_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 default staleTime of 5 minutes;
    • router.tsx refetches on window focus only after an error;
    • backend/auth/auth.ts emits 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.

Expected

  • Map the two codes:
    • TWO_FACTOR_NOT_ENABLED and TOTP_ALREADY_ENABLED get 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_ENABLED continues to the next step instead of showing an error.
  • No raw fallback: never show result.error.message. Fall back to the localized errors.*Failed texts.
  • 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

Activity

  1. added
    agent-ready
    on Oct 29, 2026
  2. added a commit that references this issue on Oct 30, 2026
    1cc8efe
  3. added a commit that references this issue on Oct 30, 2026
    a859124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions