mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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`).
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import type { RecoveryCodesSurface } from 'common/telemetry-constants'
|
|
import { ComponentProps, useState } from 'react'
|
|
import { Button } from 'ui'
|
|
|
|
import { RecoveryCodesModal } from './RecoveryCodesModal'
|
|
import { useRecoveryCodesGenerateMutation } from '@/data/recovery-codes/recovery-codes-generate-mutation'
|
|
|
|
export interface GenerateRecoveryCodesModalProps extends Pick<
|
|
ComponentProps<typeof Button>,
|
|
'variant' | 'size'
|
|
> {
|
|
label?: string
|
|
onComplete?: () => void
|
|
onStart?: () => void
|
|
surface?: RecoveryCodesSurface
|
|
showSecurityLink?: boolean
|
|
}
|
|
|
|
export const useGenerateRecoveryCodesModal = ({
|
|
label = 'Generate recovery codes',
|
|
variant,
|
|
size,
|
|
onComplete,
|
|
onStart,
|
|
surface = 'account_security',
|
|
showSecurityLink,
|
|
}: GenerateRecoveryCodesModalProps = {}) => {
|
|
const mutation = useRecoveryCodesGenerateMutation()
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const handleGenerate = () => {
|
|
onStart?.()
|
|
setIsOpen(true)
|
|
mutation.mutate({})
|
|
}
|
|
|
|
return {
|
|
trigger: (
|
|
<Button variant={variant} size={size} onClick={handleGenerate} loading={mutation.isPending}>
|
|
{label}
|
|
</Button>
|
|
),
|
|
dialog: (
|
|
<RecoveryCodesModal
|
|
open={isOpen}
|
|
mutation={mutation}
|
|
surface={surface}
|
|
showSecurityLink={showSecurityLink}
|
|
onOpenChange={(open) => {
|
|
setIsOpen(open)
|
|
if (!open && mutation.isSuccess) onComplete?.()
|
|
}}
|
|
/>
|
|
),
|
|
}
|
|
}
|
|
|
|
export const GenerateRecoveryCodesModal = (props: GenerateRecoveryCodesModalProps) => {
|
|
const { trigger, dialog } = useGenerateRecoveryCodesModal(props)
|
|
|
|
return (
|
|
<>
|
|
{trigger}
|
|
{dialog}
|
|
</>
|
|
)
|
|
}
|