## Problem
Studio tracks completion of recovery setup, but there are no events for
copying or downloading the codes.
## Solution
Track both actions in the shared recovery-code dialog. Record a copy
after the clipboard write succeeds and a download when the browser
starts it. The events carry no recovery-code values.
## Review instructions
1. Open [Recovery
codes](https://supabase.com/dashboard/account/security#recovery-codes)
on this branch's Studio preview with a disposable MFA account. Select
**Generate recovery codes** or **Regenerate** if it already has a set.
2. In **Save your recovery codes**, select **Copy**, then **Download**.
Check the browser network panel for `recovery_codes_copied` and
`recovery_codes_download_clicked` in the telemetry requests
(`telemetry/event`).
## Problem
The same recovery setup needs to work from Account Security and the new
recovery interstitial without duplicating dialog behaviour.
## Solution
Share the generation and regeneration flow, and report completion only
after codes are acknowledged or an authenticator is verified. Keep the
existing Account Security entry points. This PR provides the dialog
foundation; #52122 and #52123 consume its callbacks, and #51643 mounts
the takeover.
## Review instructions
1. Open [Account
Security](https://studio-staging-git-dnywh-recovery-shared-dialogs-supabase.vercel.app/dashboard/account/security)
in staging, or `/account/security` locally, using a disposable test
account.
2. Generate recovery codes. Confirm Done stays disabled until the save
acknowledgement is checked, then closes the dialog.
3. Regenerate codes. Cancel the confirmation first and confirm nothing
changes; repeat and confirm the replacement codes appear.
4. Open Add authenticator and cancel. Then complete enrolment with a
test authenticator; confirm it appears only after verification.
---------
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
## Context
This is largely just a mechanical change here:
Opting to use lucide icons with the `Icon` suffix across all icon
imports within `studio`
- so that it’s clearer which components are icons + reduces the
possibility of name collision with our own components
- e.g <User /> vs <UserIcon />
Also added a eslint rule for this:
<img width="1069" height="167" alt="image"
src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc"
/>
And updated `AGENTS.md` as such:
```
Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced).
```
## Context
Just a couple of UI polishes for the recovery codes UI under Account
settings -> Security - all visual, no functional changes
## Changes involved
- Shift position of Recovery codes section below MFA
- Better hierarchy since recovery codes only matter after adding an MFA
app
- Prevents layout shift with the feature flag as well
| Before | After |
|------|------|
| <img width="400" alt="image"
src="https://github.com/user-attachments/assets/3f24e30b-14b1-49cc-8942-0bd139af031b"
/> | <img width="400" alt="image"
src="https://github.com/user-attachments/assets/9a020b9b-4644-4e39-ba75-082e7f3a08db"
/> |
- Update how recovery codes are displayed
| Before | After |
|------|------|
| <img width="400" alt="image"
src="https://github.com/user-attachments/assets/9ce00013-9b7f-4ab9-9a10-0eec536022f5"
/> | <img width="400" alt="image"
src="https://github.com/user-attachments/assets/6bdc8c18-cfd2-46ea-a851-5a9fe03a5211"
/> |
- Update recovery codes modal, aligns "confirmation" UX to be more
consistent with scoped PAT
- Footer CTA is just "Done" that's disabled until either Copy or
Download is clicked
- Copy CTA shifted below codes for contextual grouping
- Also added download CTA, which just downloads codes in TXT
| Before | After |
|------|------|
| <img width="534" height="389" alt="image"
src="https://github.com/user-attachments/assets/55cdbe9f-f37c-4284-b2ac-46834fd14437"
/> | <img width="533" height="548" alt="image"
src="https://github.com/user-attachments/assets/ab091822-e5fc-464c-94e6-f1d6b6792c59"
/> |
- Show success toast after codes are successfully deleted
- Use warning variant for regenerate confirmation dialog
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Recovery codes are displayed as a numbered list, with separate options
to copy or download them.
* You must confirm that you’ve saved the codes before closing the
success dialog.
* **Improvements**
* Generation buttons show when codes are being created.
* Recovery-code actions have updated layouts, icons, and confirmation
styling. Available codes are identified as single-use, and loading
errors are displayed in an alert.
* Removing codes displays a success message before the confirmation
dialog closes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
## Problem
1. Recovery are displayed as returned by the backend
<img width="516" height="347" alt="image"
src="https://github.com/user-attachments/assets/c2599858-a65d-42d4-af3f-6bc738a810e1"
/>
2. Recovery codes are not displayed even if present when more than 1 MFA
is set up
## Solution
1. Format them as uppercased groups of 4 characters
<img width="541" height="394" alt="image"
src="https://github.com/user-attachments/assets/74c6b4eb-03c1-4de2-a772-b30ec4d7bb52"
/>
3. Fix the condition check to display recovery codes
## How to test
- Generate or regenerate your recovery codes: check the format is
correct
- If you haven't already, add a 2nd MFA: check recovery codes are still
displayed
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Improvements**
- Recovery codes are now displayed in uppercase with clear
hyphen-separated groups.
- Copied recovery codes use the same formatted presentation for easier
sharing and entry.
- The recovery codes section is available whenever recovery codes are
enabled, regardless of the number of authenticator apps configured.
- Codes that do not match the expected format remain unchanged.
- **Tests**
- Added coverage to verify consistent recovery code formatting and
clipboard behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What kind of change does this PR introduce?
Afters users set up an MFA, automatically generate recovery codes
## How to test
- On an account that doesn't have recovery codes generated yet, add a
new MFA
- When you finished verifying the MFA, it should automatically open the
recovery codes modal introduced in previous PRs
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Bug Fixes**
- Improved the two-factor authentication setup flow by checking the
latest recovery-code enrollment status before generating codes.
- Recovery codes are now generated and displayed after verification when
they are enabled but not yet enrolled.
- Loading indicators now reflect recovery-code status checks, providing
clearer feedback during setup.
- **Improvements**
- Updated the recovery-code confirmation message to explain how codes
can restore access after losing access to an MFA app and remind users to
store them securely.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What kind of change does this PR introduce?
Once users have recovery codes generated, allow them to regenerate the
codes.
This PR also automatically check the _I have copied the codes_ after
clicking the _Copy to clipboard button_.
> [!NOTE]
> The _Delete my recovery codes_ button only appear on local and staging
environments
## How to test
- On an account that already have recovery codes generated
- You should see an admonition showing the remaining codes available and
allowing you to regenerate the codes
## Screenshots
<img width="706" height="193" alt="image"
src="https://github.com/user-attachments/assets/001bfa87-74f5-4867-8564-09cb6f91adb6"
/>
<img width="425" height="277" alt="image"
src="https://github.com/user-attachments/assets/711b139c-f806-4da2-a240-fa7e7fd8acd0"
/>
<img width="548" height="353" alt="image"
src="https://github.com/user-attachments/assets/d6521a09-3a7f-4198-b162-9effc218fee6"
/>
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Added a recovery-code modal with copy-to-clipboard support and
confirmation before closing.
- Added an option to regenerate MFA recovery codes with a confirmation
step.
- Recovery-code controls now appear when existing codes are available.
- Added loading, success, error, and retry states for recovery-code
generation and regeneration.
- **Bug Fixes**
- Updated the recovery-code generation error message to more accurately
describe the failed action.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->