import { usePasskeyRegister } from '@laravel/passkeys/react'; import { useState } from 'react'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; type Props = { onSuccess: () => void; }; export default function PasskeyRegistration({ onSuccess }: Props) { const [name, setName] = useState(() => { const ua = navigator.userAgent; const browser = [ { pattern: /Edg|Edge/, name: 'Edge' }, { pattern: /OPR|Opera|OPiOS/, name: 'Opera' }, { pattern: /Firefox|FxiOS/, name: 'Firefox' }, { pattern: /Chrome|CriOS/, name: 'Chrome' }, { pattern: /Safari/, name: 'Safari' }, ].find(({ pattern }) => pattern.test(ua))?.name; const os = [ { pattern: /iPhone/, name: 'iPhone' }, { pattern: /iPad|Macintosh(?=.*Mobile)/, name: 'iPad' }, { pattern: /Android/, name: 'Android' }, { pattern: /Mac/, name: 'Mac' }, { pattern: /Windows/, name: 'Windows' }, ].find(({ pattern }) => pattern.test(ua))?.name; return [browser, os].filter(Boolean).join(' on ') || ''; }); const [showForm, setShowForm] = useState(false); const { register, isLoading, error, isSupported } = usePasskeyRegister({ onSuccess: () => { setName(''); setShowForm(false); onSuccess(); }, }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) { return; } await register(name); }; const handleCancel = () => { setShowForm(false); setName(''); }; if (!isSupported) { return (