@themodcraft/nextramice-react
v0.1.0
Published
React provider and hooks for Nextramice authentication.
Readme
@themodcraft/nextramice-react
React provider and hooks for Nextramice authentication.
Install
npm install @themodcraft/nextramice-react @themodcraft/nextramice-core reactConfigure and use
import {
NextramiceProvider,
useAuthority,
useUser,
} from "@themodcraft/nextramice-react";
export function App() {
return (
<NextramiceProvider options={{ baseUrl: "/nextramice" }}>
<UserMenu />
</NextramiceProvider>
);
}
function UserMenu() {
const user = useUser();
const isAdmin = useAuthority("ROLE_ADMIN");
return user ? <span>{user.displayName ?? user.username} {isAdmin && "(admin)"}</span> : null;
}The provider loads the session on mount by default. Set loadOnMount={false}
to control that manually. Supply backend={myBackendService} for a custom
NextramiceBackendService, or store={myStore} to own the complete store
lifecycle.
Available hooks include useAuthState, useSession, useUser,
useAuthority, and useNextramiceStore.
