{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "manage-two-factor", "dependencies": [ "@inertiajs/react" ], "registryDependencies": [ "@craft/two-factor-setup-modal", "@craft/use-two-factor-auth", "button" ], "files": [ { "path": "registry/new-york-v4/components/manage-two-factor.tsx", "content": "import { Form } from \"@inertiajs/react\";\nimport { ShieldCheck } from \"lucide-react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport Heading from \"@/components/heading\";\nimport TwoFactorSetupModal from \"@/components/two-factor-setup-modal\";\nimport { Button } from \"@/components/ui/button\";\nimport { useTwoFactorAuth } from \"@/hooks/use-two-factor-auth\";\nimport { disable, enable, show } from \"@/routes/two-factor\";\n\nexport type Props = {\n canManageTwoFactor?: boolean;\n twoFactorEnabled?: boolean;\n twoFactorPending?: boolean;\n continueTwoFactorSetup?: boolean;\n};\n\nexport default function ManageTwoFactor(props: Props) {\n const twoFactorEnabled = props.twoFactorEnabled ?? false;\n const twoFactorPending = props.twoFactorPending ?? false;\n const continueTwoFactorSetup = props.continueTwoFactorSetup ?? false;\n\n const {\n qrCodeSvg,\n hasSetupData,\n manualSetupKey,\n clearSetupData,\n clearTwoFactorAuthData,\n fetchSetupData,\n recoveryCodesList,\n errors,\n } = useTwoFactorAuth();\n const [showSetupModal, setShowSetupModal] = useState(false);\n const prevTwoFactorEnabled = useRef(twoFactorEnabled);\n\n useEffect(() => {\n if (prevTwoFactorEnabled.current && !twoFactorEnabled) {\n clearTwoFactorAuthData();\n }\n\n prevTwoFactorEnabled.current = twoFactorEnabled;\n }, [twoFactorEnabled, clearTwoFactorAuthData]);\n\n useEffect(() => {\n if (continueTwoFactorSetup && twoFactorPending) {\n setShowSetupModal(true);\n }\n }, [continueTwoFactorSetup, twoFactorPending]);\n\n if (!(props.canManageTwoFactor ?? false)) {\n return null;\n }\n\n return (\n
\n \n {twoFactorEnabled ? (\n
\n

\n You will be prompted for a secure, random pin during login, which you can\n retrieve from the TOTP-supported application on your phone.\n

\n\n
\n
\n {({ processing }) => (\n \n )}\n
\n
\n
\n ) : (\n
\n

\n When you enable two-factor authentication, you will be prompted for a secure\n pin during login. This pin can be retrieved from a TOTP-supported\n application on your phone.\n

\n\n
\n {hasSetupData ? (\n \n ) : twoFactorPending ? (\n
\n {({ processing }) => (\n \n )}\n
\n ) : (\n
setShowSetupModal(true)}>\n {({ processing }) => (\n \n )}\n
\n )}\n
\n
\n )}\n\n setShowSetupModal(false)}\n twoFactorEnabled={twoFactorEnabled}\n qrCodeSvg={qrCodeSvg}\n manualSetupKey={manualSetupKey}\n recoveryCodesList={recoveryCodesList}\n clearSetupData={clearSetupData}\n fetchSetupData={fetchSetupData}\n errors={errors}\n />\n
\n );\n}\n", "type": "registry:component" } ], "type": "registry:component" }