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.

26 lines (25 loc) 950 B
import { useCallback, useState } from 'react'; import { authenticatePasskey, submitPasskeyVerification } from '../passkey/authenticate.js'; export function usePasskeyLogin(options) { const { optionsUrl, verifyUrl, csrfToken, onSuccess } = options; const [busy, setBusy] = useState(false); const [failed, setFailed] = useState(false); const authenticate = useCallback(async () => { setFailed(false); setBusy(true); try { const assertion = await authenticatePasskey({ optionsUrl, csrfToken }); if (onSuccess) { onSuccess(assertion); setBusy(false); return; } submitPasskeyVerification({ verifyUrl, assertion, csrfToken }); } catch { setFailed(true); setBusy(false); } }, [optionsUrl, verifyUrl, csrfToken, onSuccess]); return { authenticate, busy, failed }; }