mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## 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`).
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { RefreshCwIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { Button } from 'ui'
|
|
|
|
import type { GenerateRecoveryCodesModalProps } from './GenerateRecoveryCodesModal'
|
|
import { RecoveryCodesModal } from './RecoveryCodesModal'
|
|
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
|
|
import { useRecoveryCodesRegenerateMutation } from '@/data/recovery-codes/recovery-codes-regenerate-mutation'
|
|
|
|
interface RegenerateRecoveryCodesModalProps extends GenerateRecoveryCodesModalProps {
|
|
showIcon?: boolean
|
|
}
|
|
|
|
export const useRegenerateRecoveryCodesModal = ({
|
|
label = 'Regenerate',
|
|
showIcon = true,
|
|
variant,
|
|
size,
|
|
onComplete,
|
|
onStart,
|
|
surface = 'account_security',
|
|
showSecurityLink,
|
|
}: RegenerateRecoveryCodesModalProps = {}) => {
|
|
const mutation = useRecoveryCodesRegenerateMutation()
|
|
const [stage, setStage] = useState<'idle' | 'confirm' | 'codes'>('idle')
|
|
const handleStart = () => {
|
|
onStart?.()
|
|
setStage('confirm')
|
|
}
|
|
|
|
return {
|
|
trigger: (
|
|
<Button
|
|
variant={variant}
|
|
size={size}
|
|
icon={showIcon ? <RefreshCwIcon /> : undefined}
|
|
onClick={handleStart}
|
|
loading={mutation.isPending}
|
|
>
|
|
{label}
|
|
</Button>
|
|
),
|
|
dialog: (
|
|
<>
|
|
<TextConfirmModal
|
|
visible={stage === 'confirm'}
|
|
size="small"
|
|
variant="warning"
|
|
title="Regenerate my recovery codes"
|
|
confirmPlaceholder="REGENERATE"
|
|
confirmString="REGENERATE"
|
|
confirmLabel="Regenerate"
|
|
loading={mutation.isPending}
|
|
onConfirm={() => {
|
|
setStage('codes')
|
|
mutation.mutate()
|
|
}}
|
|
onCancel={() => setStage('idle')}
|
|
>
|
|
<p className="text-sm">Your existing recovery codes won't work anymore.</p>
|
|
</TextConfirmModal>
|
|
<RecoveryCodesModal
|
|
open={stage === 'codes'}
|
|
mutation={mutation}
|
|
surface={surface}
|
|
showSecurityLink={showSecurityLink}
|
|
onOpenChange={(open) => {
|
|
if (open) return
|
|
setStage('idle')
|
|
if (mutation.isSuccess) onComplete?.()
|
|
}}
|
|
/>
|
|
</>
|
|
),
|
|
}
|
|
}
|
|
|
|
export const RegenerateRecoveryCodesModal = (props: RegenerateRecoveryCodesModalProps) => {
|
|
const { trigger, dialog } = useRegenerateRecoveryCodesModal(props)
|
|
|
|
return (
|
|
<>
|
|
{trigger}
|
|
{dialog}
|
|
</>
|
|
)
|
|
}
|