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.
Theming
Both ConnectButton and LoginModal default to the green Calimero palette used in admin-dashboard, tauri-app, and app-registry. No theme prop is required — pass nothing and you get the default look. Provide a partial MeroTheme to override any subset of tokens.
primary?: string; // CTA color — default '#a5ff11'
primaryHover?: string; // default '#8ed40d'
primaryText?: string; // text on top of primary — default '#0d1117'
background?: string; // modal/button surface — default '#0d1117'
backgroundSecondary?: string;// inputs, info chips — default '#161b22'
backgroundTertiary?: string; // default '#1c2128'
border?: string; // default '#30363d'
text?: string; // default '#e6edf3'
textSecondary?: string; // default '#8b949e'
error?: string; // default '#ff6b6b'
overlay?: string; // modal backdrop — default 'rgba(0, 0, 0, 0.75)'
radius?: string; // default '8px'
}
Default usage — green Calimero palette:
Override a few tokens — only the keys you provide are changed; the rest keep the defaults:
theme={{
primary: '#ff4081',
primaryHover: '#e91e63',
primaryText: '#ffffff',
}}
/>
CSS variable override — same tokens are also exposed as CSS variables on the component root, so global stylesheets work too:
:root {
--mero-accent: #ff4081;
--mero-accent-hover: #e91e63;
}
Helpers — exported alongside the type:
// defaultMeroTheme: the full green palette as a frozen object
// resolveMeroTheme(partial?): returns a fully populated ResolvedMeroTheme