Client
This content is for the 0.2.0-alpha.3 version. Switch to the latest version for up-to-date documentation.
import { Client } from "@muhkoo/connect";
const client = new Client(options);new Client(options)
Section titled “new Client(options)”| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | recommended | — | App key (mk_…). Sent as X-Muhkoo-Key. |
baseUrl | string | no | the hosted accelerator | Absolute accelerator URL. Trailing slash optional. |
circuits | { wasmUrl: string; zkeyUrl: string } | no | ${baseUrl}/circuits/build/preimagePoK{.wasm,_0001.zkey} | ZK circuit assets for login proofs. |
sessionStore | SessionStore | no | in-memory | Session-token persistence. |
fetch | typeof fetch | no | globalThis.fetch | Custom fetch. |
logLevel | string | no | — | SDK log verbosity. |
All options are optional — new Client() targets the hosted accelerator with an
in-memory session.
Namespaces
Section titled “Namespaces”| Property | Type | Description |
|---|---|---|
client.auth | AuthNamespace | Authentication — see client.auth. |
client.storage | StorageNamespace | Encrypted KV — see client.storage. |
client.message | MessageNamespace | Realtime pub/sub — see client.message. |
client.space | SpaceNamespace | Group channels — see client.space. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
client.user | { username: string; commitment: string } | null | The signed-in user (sync read). |
client.isAuthenticated | boolean | Whether a session token is active (sync read). |
client.baseUrl | string | The normalized accelerator URL. |
Session recovery
Section titled “Session recovery”When a token-gated request comes back 401 (the session went stale), the client
silently re-authenticates if it still holds the user’s identity (i.e. they
logged in this session and never reloaded), then retries the request — so a
transient expiry self-heals without surfacing an error.
| Method | Signature | Description |
|---|---|---|
client.recoverSession() | () => Promise<boolean> | Attempt a silent re-auth now. Concurrent calls share one attempt. Resolves true on success. Call proactively if you like (e.g. on visibilitychange). |
client.onSessionExpired(handler) | (() => void) => () => void | Fires when recovery isn’t possible — typically after a reload that kept only a now-stale token. This is your cue to route the user to the login screen. Returns an unsubscribe fn. |
const off = client.onSessionExpired(() => router.push("/login"));SessionStore
Section titled “SessionStore”interface StoredSession { token: string; username: string; commitment: string;}
interface SessionStore { load(): StoredSession | null | Promise<StoredSession | null>; save(session: StoredSession): void | Promise<void>; clear(): void | Promise<void>;}The SDK ships MemorySessionStore (the default). Provide your own to persist
across reloads — see Installation.