"use client"; import { useState } from "react"; import { useOnboarding } from "@onboardjs/react"; import { KeyRound, ShieldCheck } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; import { useMutation } from "@tanstack/react-query"; import { toast } from "sonner"; import { authClient } from "@/lib/auth/auth-client"; import { TwoFactorSetupContent } from "@/features/profile/components/two-factor-setup-content"; import type { OnboardingMeta } from "@/features/onboarding/types"; export const StepSecurity = () => { const { next, updateContext, state } = useOnboarding(); const meta = state?.context.flowData.meta as OnboardingMeta | undefined; const passkeyEnabled = meta?.passkeyEnabled ?? false; const [phase, setPhase] = useState<"choose" | "two-factor">("choose"); const { mutate: addPasskey, isPending: isAddingPasskey } = useMutation({ mutationFn: async () => { const result = await authClient.passkey.addPasskey({ name: "My Passkey" }); if (result?.error) throw result.error; return result; }, onSuccess: async () => { toast.success("Passkey added successfully."); await updateContext({ flowData: { ...state?.context.flowData, security: { method: "passkey" } } }); await next(); }, onError: (e: any) => toast.error(e.message || "Failed to add passkey"), }); const handleTwoFactorSuccess = async () => { await updateContext({ flowData: { ...state?.context.flowData, security: { method: "two-factor" } } }); await next(); }; if (phase === "two-factor") { return (

Set up two-factor

Add an extra layer of security to your account.

); } return (

Secure your account

Choose a method to protect your account.

{passkeyEnabled && ( )}
); };