import { Plus } from 'lucide-react' import { useState } from 'react' import { passkeySupported, registerPasskey, type PasskeyPlace } from '@shared/api/webauthn' import { guessPlatform, useAction, useToast } from '@shared/ui' /** 默认的 passkey 名称:按浏览器所在的系统给一个能认出来的名字。 */ function defaultName(): string { const platform = guessPlatform() return platform === 'windows' ? 'Windows 设备' : platform === 'macos' ? 'Mac' : 'Linux 设备' } /** * 添加 passkey 的表单:名称 + 保存位置 + 按钮。「我的 Passkey」和登录后的提醒共用同一份。 * 保存位置只是给浏览器的提示:`device` 优先用设备或浏览器账户自带的(Chrome 里是 Google 密码管理工具、Windows Hello), * `external` 是安全密钥或手机扫码。 */ export function PasskeyAddForm({ onAdded, compact }: { onAdded: () => void; compact?: boolean }) { const { busy, run } = useAction() const toast = useToast() const [name, setName] = useState(defaultName) const [place, setPlace] = useState('device') const supported = passkeySupported() return (
setName(e.target.value)} disabled={!supported} />
) }