Files
supabase/apps/studio/components/interfaces/Account/TOTPFactors/RecoveryCodesAvailable.tsx
Danny White b83ad78d77 feat(studio): show recovery code health in account security (#52355)
## Problem

Users can run out of recovery codes without a clear warning that they
have lost a backup way to sign in.

## Solution

Show a warning when codes are running low or used up, with Regenerate
beside the code count. When MFA is enabled but codes are missing,
explain how to generate them. Keep recovery codes hidden until MFA is
enabled.

Remove standalone code deletion. Users can regenerate codes while MFA is
enabled.

| Before | After |
| --- | --- |
| <img width="1024" height="682" alt="Security Account Supabase"
src="https://github.com/user-attachments/assets/1c7a4c52-00c9-4c31-8b3a-ef0599555a1a"
/> | <img width="1024" height="682" alt="81082"
src="https://github.com/user-attachments/assets/ae662802-4fab-4c93-a5cb-52ed39d16f87"
/> |
| _3/10 codes left._ | _3/10 codes left._ |
| <img width="1024" height="682" alt="21450"
src="https://github.com/user-attachments/assets/82049f44-2fca-4477-84bf-23ab009868be"
/> | <img width="1024" height="682" alt="Security Account Supabase"
src="https://github.com/user-attachments/assets/e2185026-af6a-42a5-bc10-b587e3d2d4ab"
/> |
| _0/10 codes left._ | _0/10 codes left._ |

## Review instructions

1. Open [Recovery
codes](https://studio-staging-git-dnywh-recovery-code-health-supabase.vercel.app/dashboard/account/security#recovery-codes)
with one authenticator and generated codes.
2. In DevTools, override GET `/factors/recovery-codes`: keep the other
fields, set `remaining` to `0`, save and reload. Check the warning.
Repeat with `3`, then restore the response.
3. With MFA off, check that the Recovery codes section is hidden.
Disable overrides before using Regenerate.
2026-11-09 17:34:51 +11:00

58 lines
2.0 KiB
TypeScript

import type { AuthMFARecoveryCodesStatusResponseData } from '@supabase/supabase-js'
import { RectangleEllipsisIcon } from 'lucide-react'
import type { ReactNode } from 'react'
import { Card, CardContent } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import type { AccountRecoveryFinding } from '@/lib/account-recovery/evaluate-account-recovery'
interface RecoveryCodesAvailableProps {
codes: AuthMFARecoveryCodesStatusResponseData
finding: AccountRecoveryFinding | undefined
children: ReactNode
}
export const RecoveryCodesAvailable = ({
codes,
finding,
children,
}: RecoveryCodesAvailableProps) => {
return (
<>
{finding && (
<Admonition
type={finding.severity === 'critical' ? 'destructive' : 'warning'}
title={
finding.id === 'recovery-codes-exhausted'
? 'Recovery codes used up'
: `${codes.remaining} recovery ${codes.remaining === 1 ? 'code' : 'codes'} remaining`
}
description={
finding.id === 'recovery-codes-exhausted'
? 'Generate a new set so you have a backup way to sign in.'
: 'Generate a new set before you need them to recover your account.'
}
/>
)}
<Card>
<CardContent className="flex flex-wrap items-center justify-between gap-4">
<div className="flex items-center gap-x-4">
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-selection">
<RectangleEllipsisIcon size={18} className="text-foreground-lighter" />
</div>
<div className="text-sm">
<p>
{codes.remaining} of {codes.total} recovery codes available
</p>
<p className="text-foreground-lighter">
Each code can only be used once. Keep them somewhere safe.
</p>
</div>
</div>
{children}
</CardContent>
</Card>
</>
)
}