'use client'; import { useCallback, useEffect, useState } from 'react'; import { authClient } from '@/app/lib/auth-client'; type Key = { id: string; name?: string | null; createdAt?: string | Date | null }; // Shown to signed-in people: save a passkey (the only way to sign in), add a // second one on another device as a way back in, or remove one. export function PasskeyPanel({ compact = false }: { compact?: boolean }) { const [keys, setKeys] = useState(null); const [busy, setBusy] = useState(false); const [msg, setMsg] = useState(null); const load = useCallback(async () => { const res = await authClient.passkey.listUserPasskeys(); setKeys((res.data as Key[] | null) ?? []); }, []); useEffect(() => { load().catch(() => setKeys([])); }, [load]); async function add() { setBusy(true); setMsg(null); try { const res = await authClient.passkey.addPasskey({ name: navigator.platform || 'Passkey' }); if (res?.error) setMsg('The passkey wasn’t saved. Try again.'); else { setMsg('Passkey saved. Next time, just tap Sign in with passkey.'); await load(); } } finally { setBusy(false); } } async function remove(id: string) { await authClient.passkey.deletePasskey({ id }); await load(); } if (keys === null) return null; if (compact && keys.length > 0) return null; return (

Passkeys

{keys.length === 0 ? 'Save a passkey so you can get back here any time with Face ID, Touch ID or your phone.' : 'Add a second passkey on another device so you always have a way back in.'}

{keys.map((k) => (

{k.name || 'Passkey'}{' '}

))} {msg &&

{msg}

}
); }