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.

20 lines (19 loc) 895 B
import { createElement } from 'react'; import { interactionUrls } from '../interaction/urls.js'; function lockOnSubmit(event, hostOnSubmit) { const formEvent = event; hostOnSubmit?.(formEvent); const form = formEvent.currentTarget; setTimeout(() => { if (formEvent.defaultPrevented) return; for (const el of form.querySelectorAll('button[type="submit"], input[type="submit"]')) { el.disabled = true; } form.setAttribute('aria-busy', 'true'); }, 0); } export function InteractionForm({ uid, step, csrfToken, basePath, children, onSubmit, ...rest }) { const action = interactionUrls(uid, basePath)[step]; return createElement('form', { method: 'POST', action, onSubmit: (event) => lockOnSubmit(event, onSubmit), ...rest }, createElement('input', { type: 'hidden', name: '_csrf', value: csrfToken }), children); }