import { Trans } from "@lingui/react/macro"; import { KeyIcon, LockOpenIcon, ToggleLeftIcon, ToggleRightIcon } from "@phosphor-icons/react"; import { motion } from "motion/react"; import { useCallback, useMemo } from "react"; import { match } from "ts-pattern"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { useDialogStore } from "@/dialogs/store"; import { authClient } from "@/integrations/auth/client"; import { useAuthAccounts } from "./hooks"; export function TwoFactorSection() { const { openDialog } = useDialogStore(); const { hasAccount } = useAuthAccounts(); const { data: session } = authClient.useSession(); const hasPassword = useMemo(() => hasAccount("credential"), [hasAccount]); const hasTwoFactor = useMemo(() => session?.user.twoFactorEnabled ?? false, [session]); const handleTwoFactorAction = useCallback(() => { if (hasTwoFactor) { openDialog("auth.two-factor.disable", undefined); } else { openDialog("auth.two-factor.enable", undefined); } }, [hasTwoFactor, openDialog]); if (!hasPassword) return null; return (

{hasTwoFactor ? : } Two-Factor Authentication

{match(hasTwoFactor) .with(true, () => ( )) .with(false, () => ( )) .exhaustive()}
); }