@companyio/auth-react
v0.1.33
Published
React provider and hooks for the shared authentication platform
Readme
@companyio/auth-react
React context for sharing an AuthClient, restoring sessions on startup, and reading the current user.
Public API
AuthProvider— wraps the tree; callsclient.restore()once and subscribes to session changesuseAuth()— returns{ client, session, user, isLoading, signIn, signOut }(throws outside the provider)
Use
import { AuthProvider, useAuth } from '@companyio/auth-react';
<AuthProvider client={authClient}>
<App />
</AuthProvider>;
function Account() {
const { user, isLoading, signOut } = useAuth();
return isLoading ? <span>Loading...</span> : <button onClick={signOut}>{user?.email}</button>;
}This package is a thin React binding over @companyio/auth-client. Auth rules and tenant fields live in contracts / the API host.
Build / test
pnpm --filter @companyio/auth-react test
pnpm --filter @companyio/auth-react build