@namoidhq/react
@namoidhq/react wraps @namoidhq/js in React components and
hooks so you can drop NamoID sign-in into a React app without wiring the client
yourself.
- Package:
@namoidhq/react - Peer deps:
react >= 18,react-dom >= 18
Install
npm install @namoidhq/react @namoidhq/js
Provide the client
Wrap your app in NamoIDProvider. It accepts the same options as
createNamoIDClient:
import { NamoIDProvider } from "@namoidhq/react";
export function App({ children }) {
return (
<NamoIDProvider
publishableKey="namoid_auth_pk_live_…"
// apiBaseUrl / hostedLoginBaseUrl / fetcher optional
>
{children}
</NamoIDProvider>
);
}
Hooks
useNamoID()— returns the initializedNamoIDClientfrom context. Throws if used outside aNamoIDProvider.useAuthConfig()— returns{ config, loading, error, reload }, auto-fetching your environment's auth config on mount with a manualreload().
import { useAuthConfig } from "@namoidhq/react";
function Methods() {
const { config, loading } = useAuthConfig();
if (loading) return <p>Loading…</p>;
return <p>Methods: {config?.signin_methods.join(", ")}</p>;
}
Components
All take at least clientId and redirectUri.
HostedLoginButton— a button that redirects to hosted login. Props are theHostedLoginUrlOptionsplusmode("signin" | "signup" | "waitlist"),children,className,style,disabled. Disabled untilclientIdandredirectUriare set; the default label depends onmode.SignIn— a card with a sign-in button; enabled when the environment has at least one sign-in method.SignUp— a card for registration; enabled when access mode isn't closed.Waitlist— an email-capture form; with anonSubmitEmailhandler it submits locally, otherwise it renders aHostedLoginButtoninwaitlistmode.AuthCard— chooses betweenSignIn/SignUp/Waitlistbased on amodeprop.
import { SignIn, SignUp, Waitlist, HostedLoginButton } from "@namoidhq/react";
<>
<SignIn clientId="idpc_live_…" redirectUri="https://app.example/auth/callback" />
<SignUp clientId="idpc_live_…" redirectUri="https://app.example/auth/callback" />
<Waitlist clientId="idpc_live_…" redirectUri="https://app.example/auth/callback" />
<HostedLoginButton clientId="idpc_live_…" redirectUri="https://app.example/auth/callback" mode="signin" />
</>
How it fits with your server
These components handle the front-channel redirect into hosted login. Your
server still completes the OIDC code exchange — in Next.js, pair this with
@namoidhq/nextjs or any conformant OIDC library such as
Auth.js.