import { Client } from " @muhkoo/connect " ;
const client = new Client (options);
Option Type Required Default Description apiKeystringrecommended — App key (mk_…). Sent as X-Muhkoo-Key. baseUrlstringno 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. sessionStoreSessionStoreno in-memory Session-token persistence. fetchtypeof fetchno globalThis.fetchCustom fetch. logLevelstringno — SDK log verbosity. offline{ enabled?, store?, cacheShards?, maxQueueBytes? }no auto (on in browsers) Offline cache + sync. On by default in browsers, no-op elsewhere.accessTokenstringno — Machine credential (mk_…_at_…) in place of a user sign-in — see access tokens . authBaseUrlstringno auth.muhkoo.devOverride the hosted sign-in origin (staging/dev only). functionsHostSuffixstringno the hosted functions domain Override where client.functions resolves function URLs. p2p{ enabled?, workerFactory?, iceServers?, maxPeers?, debug? }no off Peer-to-peer shard exchange between members of a Space — see storage .
All options are optional — new Client() targets the hosted accelerator with an
in-memory session.
Property Type Description client.authAuthNamespaceAuthentication — see client.auth . client.kvKvNamespaceEncrypted key/value — see client.kv . client.dbDbNamespaceScalable app database — see client.db . client.storageStorageNamespaceFile storage — see client.storage . client.vfsVfsNamespaceThe user’s filesystem: directories, paths, versions — see client.vfs . client.messageMessageNamespaceRealtime pub/sub — see client.message . client.spaceSpaceNamespaceGroup channels — see client.space . client.offlineOfflineManagerOffline cache, status & snapshots — see client.offline . client.agentsAgentsNamespaceProgrammable Agents — see client.agents . client.functionsFunctionsNamespaceServerless functions — see client.functions . client.accessTokensAccessTokensNamespaceScoped machine credentials — see access tokens .
Property Type Description client.user{ username: string; commitment: string } | nullThe signed-in user (sync read). client.isAuthenticatedbooleanWhether a session token is active (sync read). client.baseUrlstringThe normalized accelerator URL.
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) => () => voidFires 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 " ));
interface StoredSession {
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 .