UNPKG

@adonis-agora/authkit-react

Version:

Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.

24 lines (23 loc) 997 B
import { createElement } from 'react'; import { usePasskeyLogin } from '../hooks/use_passkey_login.js'; import { buttonClass } from '../utils.js'; const DEFAULT_ERROR = 'Não foi possível autenticar com a passkey. Tente novamente.'; export function PasskeyButton({ optionsUrl, verifyUrl, csrfToken, children = 'Entrar com passkey', errorContent, className, ...rest }) { const { authenticate, busy, failed } = usePasskeyLogin({ optionsUrl, verifyUrl, csrfToken, }); const button = createElement('button', { type: 'button', className: buttonClass('authkit-button--ghost', className), onClick: () => { void authenticate(); }, disabled: busy, ...rest, }, children); if (!failed || errorContent === null) return button; return createElement('div', { className: 'authkit-passkey' }, button, createElement('p', { className: 'authkit-passkey__error' }, errorContent ?? DEFAULT_ERROR)); }