@adonis-agora/authkit-react
Version:
Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.
17 lines (16 loc) • 694 B
JavaScript
import { createElement } from 'react';
import { useSignIn } from '../hooks/use_sign_in.js';
import { useAuth } from '../use_auth.js';
export function SignInButton({ children = 'Entrar', returnTo, showWhenAuthenticated = false, className, ...rest }) {
const { signIn } = useSignIn();
const { isAuthenticated } = useAuth();
if (isAuthenticated && !showWhenAuthenticated)
return null;
const opts = returnTo ? { returnTo } : undefined;
return createElement('button', {
type: 'button',
className: ['authkit-button', 'authkit-button--primary', className].filter(Boolean).join(' '),
onClick: () => signIn(opts),
...rest,
}, children);
}