Files
supabase/apps/studio/components/interfaces/Account/TOTPFactors/useRecoveryCodesGate.ts
Danny WhiteandJoshen Lim c7b49e2b1b feat(studio): resume account actions after recovery-code verification (#52747)
## Problem

Recovery-code verification uses a separate sign-in layout and returns
users to Security without resuming the selected action.

## Solution

Visually align with other security checks: use InterstitialLayout and
return to the selected authenticator’s removal confirmation. Cancel
returns to Security without signing out. Verification never removes the
authenticator automatically.

| Before | After |
| --- | --- |
| <img width="1280" height="1323" alt="Supabase"
src="https://github.com/user-attachments/assets/404e7b6d-6fe6-492a-b853-dc3b13b8f767"
/> | <img width="1280" height="1323" alt="47214"
src="https://github.com/user-attachments/assets/0100cf2f-3252-4f5c-a3a6-17bb0d81dfa5"
/> |

| After |
| --- |
| <img width="1280" height="1323" alt="45032"
src="https://github.com/user-attachments/assets/584254e2-0772-4dae-a0e5-9be6a8f99239"
/> |
| _Loading state._ |
| <img width="1280" height="1323" alt="8565"
src="https://github.com/user-attachments/assets/6d14459d-f172-4338-a021-fb5721649fda"
/> |
| _Standard unfilled state._ |
| <img width="1280" height="1323" alt="47304"
src="https://github.com/user-attachments/assets/83eca080-0fb6-4b3e-a52b-0110c6f8714a"
/> |
| _Error state. I’ve removed `font-mono` since this screenshot._ |

This PR also includes the _Use recovery code instead_ option into the
prior PR’s _Verify your identity_ interstitial:

| After |
| --- |
| <img width="1280" height="763" alt="6526"
src="https://github.com/user-attachments/assets/a05e3bc5-061d-4297-9fd0-e456dba44d4a"
/> |
| _Addition of the _Use recovery code instead_ button._ |


## Review instructions

Use a disposable MFA account with saved recovery codes. Successful
verification consumes one code.

1. Open [Security on this
preview](https://studio-staging-git-dnywh-recovery-code-verification-supabase.vercel.app/dashboard/account/security).
Follow [#52352’s breakpoint
steps](https://github.com/supabase/supabase/pull/52352#review-instructions)
on this preview to show Verify your identity. Remove the breakpoint
before continuing.
2. Choose Use a recovery code instead. Check the code visibility control
and an invalid-code error, then enter a valid saved code. The selected
authenticator’s removal confirmation should open. Nothing is deleted
until you click Remove.
3. Repeat and Cancel on the recovery-code screen. Return to Security and
remain signed in.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-11-09 16:35:32 +11:00

33 lines
1.1 KiB
TypeScript

import { useFlag } from 'common'
import { useRecoveryCodesStatusQuery } from '@/data/recovery-codes/recovery-codes-status-query'
/**
* Recovery code state that gates removing an MFA method. The status query is shared through the
* query cache, so every caller sees the same data without it being passed down as props.
*/
export const useRecoveryCodesGate = ({ enabled = true }: { enabled?: boolean } = {}) => {
const enableAuthRecoveryCodes = useFlag('enableAuthRecoveryCodes')
const isActive = enableAuthRecoveryCodes && enabled
const { data, error, isError, isPending, isFetching, refetch } = useRecoveryCodesStatusQuery({
enabled: isActive,
})
const { data: codes, status } = data ?? {}
return {
isActive,
codes,
status,
error,
isError,
isPending,
isFetching,
refetch,
hasRecoveryCodes: status === 'available',
canUseRecoveryCodes: isActive && status === 'available' && !!codes && codes.remaining > 0,
// Removing an MFA method requires knowing the recovery code status first
canRemoveFactor: !(isActive && (isPending || isFetching || isError || !status)),
}
}