Skip to content

feat: add Phoenix integration for recovery code strategy#724

Merged
jimsynz merged 13 commits intomainfrom
add-recovery-code-phoenix
Apr 12, 2026
Merged

feat: add Phoenix integration for recovery code strategy#724
jimsynz merged 13 commits intomainfrom
add-recovery-code-phoenix

Conversation

@jimsynz
Copy link
Copy Markdown
Collaborator

@jimsynz jimsynz commented Apr 9, 2026

Summary

  • Adds LiveViews, components, router macros, and overrides for recovery code authentication
  • Adds enforcement plugs (RequireRecoveryCodes) and LiveSession hooks
  • Adds DaisyUI overrides for all recovery code components
  • Adds cross-link between TOTP verify and recovery code verify pages
  • Adds igniter generator that wires up routes, auth controller clause, and override configuration
  • Adds tutorial documentation following the Diataxis framework

Companion PR

Depends on team-alembic/ash_authentication#1135 which adds the core recovery code strategy.

Test plan

  • Full end-to-end flow tested with Playwright: register -> TOTP setup -> sign out -> sign in -> TOTP verify -> "Use a recovery code" -> enter code -> authenticated
  • Cross-links between TOTP and recovery code verify pages preserve auth token
  • Nil actor returns proper error instead of crashing
  • mix check passes
  • Igniter generates routes, controller clause, and overrides correctly

jimsynz added 13 commits April 9, 2026 10:06
Add LiveViews, components, router macros, and overrides for recovery
code authentication:

- `RecoveryCodeVerifyLive` + `VerifyForm` — verification page with
  token-based and step-up modes (mirrors TOTP verify flow)
- `RecoveryCodeDisplayLive` + `DisplayCodes` — code generation and
  display page for authenticated users
- `RecoveryCode.Input` — function components for recovery code forms
- `recovery_code_verify_route/3` and `recovery_code_display_route/3`
  router macros
- Cross-link from TOTP verify page to recovery code verify page via
  overridable `recovery_code_link_path` on `Verify2faForm`
- Default and override registrations for all new components
- `RecoveryCodeHelpers` — helper functions for checking if a user has
  recovery codes configured
- `Plug.RequireRecoveryCodes` — plug to enforce recovery code setup,
  with halt/redirect options (mirrors `Plug.RequireTotp` pattern)
- `LiveSession.RequireRecoveryCodes` — LiveView on_mount hook for the
  same purpose
Add recovery code overrides to both default (Tailwind) and DaisyUI
override modules. Also adds the recovery code cross-link overrides
to the TOTP Verify2faForm in DaisyUI.
Adds `mix ash_authentication_phoenix.add_strategy.recovery_code` task
that adds `recovery_code_verify_route` and `recovery_code_display_route`
to the router. Registered in the main `add_strategy` dispatcher so
`mix ash_authentication_phoenix.add_strategy recovery_code` works.
Modify the auth controller's success/4 to match on the :confirm_setup
phase and redirect to /recovery-codes, so users are prompted to generate
recovery codes immediately after setting up TOTP.
The recovery code igniter now:
- Sets recovery_code_link_path on the TOTP Verify2faForm override so
  the "Use a recovery code instead" link appears on the TOTP verify page
- Sets totp_link_path on the RecoveryCode VerifyForm override so the
  "Use authenticator app instead" link appears on the recovery code page
- Adds a success/4 clause for :confirm_setup redirecting to /recovery-codes
- Registers in the install task's @phoenix_strategy_tasks map
- Tutorial: covers routes, cross-linking with TOTP, auth controller
  integration, metadata, enforcement plugs, and helper functions
- Update TOTP 2FA guide to reference recovery codes instead of generic
  "backup codes" section
@jimsynz jimsynz merged commit feb081a into main Apr 12, 2026
44 of 47 checks passed
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.

1 participant