@adonis-agora/authkit-react
Version:
Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.
35 lines (34 loc) • 1.67 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createElement } from 'react';
import { useAuthkitConfig } from '../config.js';
import { useAuthorizedApps } from '../hooks/use_authorized_apps.js';
function AuthorizedAppsInner({ className, revokeLabel = 'Revogar', emptyLabel = 'Nenhum app autorizado.', }) {
const { data, loading, error, actions } = useAuthorizedApps();
if (loading && !data) {
return createElement('div', { className: 'authkit-apps__loading' }, 'Carregando…');
}
if (error) {
return createElement('p', { className: 'authkit-error', role: 'alert' }, error.message);
}
const apps = data ?? [];
if (apps.length === 0) {
return createElement('p', { className: 'authkit-apps__empty' }, emptyLabel);
}
return createElement('ul', { className: ['authkit-apps', className].filter(Boolean).join(' ') }, ...apps.map((app) => createElement('li', { key: app.clientId, className: 'authkit-apps__item' }, createElement('div', { className: 'authkit-apps__info' }, app.logoUrl
? createElement('img', {
className: 'authkit-apps__logo',
src: app.logoUrl,
alt: '',
})
: null, createElement('span', { className: 'authkit-apps__name' }, app.name ?? app.clientId)), createElement('button', {
type: 'button',
className: 'authkit-button authkit-button--danger',
onClick: () => void actions.revoke(app.clientId),
}, revokeLabel))));
}
export function AuthorizedApps(props) {
const { idp } = useAuthkitConfig();
if (idp === 'external')
return null;
return _jsx(AuthorizedAppsInner, { ...props });
}