Skip to content

feat(identity): recovery codes status + download/print (closes #180)#203

Open
antosubash wants to merge 1 commit into
mainfrom
issue-180-recovery-codes
Open

feat(identity): recovery codes status + download/print (closes #180)#203
antosubash wants to merge 1 commit into
mainfrom
issue-180-recovery-codes

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

Closes #180.

  • 2FA management page now shows a neutral status row "Recovery codes: N remaining" when recoveryCodesLeft >= 4. The existing alerts at <=3, =1, and =0 (warning / danger styles) are kept — those already handled the low-stock case.
  • ShowRecoveryCodes page gains Download (.txt) and Print buttons:
    • Download writes a header line (SimpleModule recovery codes — generated for <email> on <date>) followed by the 10 codes, one per line, named simplemodule-recovery-codes.txt.
    • Print uses an inline @media print stylesheet that hides everything outside the codes block and re-styles the codes as black-on-white monospace.
  • Both render paths in AccountSecurityEndpoint (initial 2FA enable that auto-generates codes, and explicit "Reset recovery codes") now thread userEmail + generatedAt so the header is accurate.
  • Added a comment on GenerateRecoveryCodesEndpoint explaining that codes are hashed (like passwords) and the only honest paths are download/print at generation time or regenerate (invalidates prior set). Prevents future contributors from inventing a retrieve-existing-codes endpoint that can't actually exist.

Test plan

  • dotnet build — green
  • dotnet test modules/Users/tests — 70/70
  • Manual smoke: enable 2FA → see codes screen → Download writes a file with the header + codes; Print shows codes only (no nav/buttons). Reset recovery codes from the 2FA page → same behavior. With 7 codes remaining, the 2FA page shows "Recovery codes: 7 remaining" as a plain text-text-muted line; redeem until at 3 remaining and the existing warning takes over.

Not in scope

  • A separate translation file beyond en.json. The codebase only ships English today; other languages will pick up the new keys when their files exist.
  • Recovery-code redemption tests — covered by the existing LoginWithRecoveryCodeEndpoint tests; CountRecoveryCodesAsync is the Identity primitive and is not re-wrapped here.

- 2FA management page now shows 'Recovery codes: N remaining' as a
  neutral status row when count is >= 4. The existing low-threshold
  alerts at <=3, 1, and 0 are kept.
- ShowRecoveryCodes page gains Download (.txt) and Print buttons.
  Download writes a header line (user email + generated-at) followed
  by the codes.
- Print uses an inline @media print stylesheet that hides chrome and
  re-styles the codes block as black-on-white monospace.
- Both render paths in AccountSecurityEndpoint now thread userEmail
  and generatedAt through so the header is accurate.
- Added a comment on GenerateRecoveryCodesEndpoint explaining that
  codes are hashed (like passwords) and the only honest paths are
  'download/print at generation time' or 'regenerate (invalidates
  prior set)'. Prevents future contributors from trying to add a
  retrieve-existing-codes endpoint.

No new API contracts; UI-only + props passthrough. Existing Users
suite still 70/70.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 212829b
Status: ✅  Deploy successful!
Preview URL: https://1a395c78.simplemodule-website.pages.dev
Branch Preview URL: https://issue-180-recovery-codes.simplemodule-website.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identity: recovery codes status &amp; download

1 participant