MeroProvider
Context provider that creates the SDK instance and manages connection state
Usage
Wrap your application once at the root. All hooks must be used inside a MeroProvider.
function Root() {
return (
<MeroProvider
mode={AppMode.SingleContext}
packageName="com.example.myapp"
>
<App />
</MeroProvider>
);
}
MeroProviderProps
AppMode
Controls how the provider initialises and which context is active.
AppMode.SingleContext // 'single-context'
AppMode.MultiContext // 'multi-context'
AppMode.Admin // 'admin'
ConnectionType
Used with ConnectButton and LoginModal to control which node URLs are offered.
// Use with ConnectButton:
<ConnectButton connectionType={ConnectionType.Remote} />
MeroContextValue — useMero() return type
mero: MeroJs | null; // SDK instance (null before connected)
isAuthenticated: boolean; // true when tokens are present
isOnline: boolean; // true when node is reachable
isLoading: boolean; // true during initialisation
nodeUrl: string | null; // current node URL
applicationId: string | null; // current application ID
contextId: string | null; // active context ID
contextIdentity: string | null;// context identity (executor public key)
connectToNode: (url: string) => void; // set node URL and init
logout: () => void; // clear tokens and disconnect
}
SSO — Tokens from URL Hash
When your app is opened from Calimero Desktop, the provider automatically reads tokens from the URL hash via parseAuthCallback(window.location.href) and stores them in the internal token store. You don't need to do anything extra — the provider handles it.
// https://app.example.com/#access_token=...&node_url=...&context_id=...&context_identity=...
// MeroProvider reads these automatically on mount.
// useMero().isAuthenticated will be true immediately.
ConnectButton
Drop-in button that shows connection status and handles the full connect/disconnect flow. Uses ConnectionType to decide whether to show the LoginModal or connect directly.
// Show modal with local + remote options (default)
<ConnectButton />
// Remote-only
<ConnectButton connectionType={ConnectionType.Remote} />
// Skip modal — connect directly to a URL
<ConnectButton connectionType={{ type: ConnectionType.Custom, url: 'http://localhost:4001' }} />
States: Disconnected — shows Connect button and opens LoginModal. Connected — shows Connected + dropdown (node URL, Dashboard link, Log out). Reconnecting — disabled button while SSE reconnects.
LoginModal
Modal dialog for node URL selection. Used internally by ConnectButton but also available standalone for custom connect flows.
<LoginModal
isOpen={showModal}
onConnect={(url) => { connectToNode(url); setShowModal(false); }}
onClose={() => setShowModal(false)}
connectionType={ConnectionType.RemoteAndLocal}
/>
(url: string) => void — called with the resolved node URL.() => void — called when the modal is dismissed.Rendered via createPortal at document.body — unaffected by parent overflow or z-index. Uses inline styles, no external CSS dependency.