jaza.consume.
Flow
- User signs in to your app
- App calls your
POST /api/jaza/init(or similar) - Host resolves
customerIdand callsjaza.init({ customerId }) - Host returns
InitResult(sessionToken, wallet/features snapshot, expiry) JazaProviderstores the session and calls Jaza client APIs with the session JWT + publishable key
Host route
InitResult includes at least:
Create the customer once at signup with
jaza.createCustomer, then store customer.id on your user row.
Provider wiring
PrefergetSession: a function that hits your init route and returns InitResult.
authEndpoint alternative
Pass a URL instead of a function. The SDK POSTs that endpoint and expects the same InitResult JSON. If both are set, getSession wins.
Legacy getBalance
getBalance alone still works for older apps, but you should migrate to getSession / authEndpoint so top-up and ledger use the client session. Do not treat host-minted top-up JWTs (onRequestToken) as the primary path.
Session lifecycle
- After init, the SDK refreshes wallet/ledger via client routes (
GET /v1/client/wallet, etc.) - On 401 from a client API, the SDK re-runs the handshake once
- If re-init fails → status
UNAUTHENTICATEDandonAuthError - Use
useJaza().status(INITIALIZING|AUTHENTICATED|UNAUTHENTICATED|ERROR) to gate your UI
Security checklist
- Secret key only on the host
- Init route requires your app authentication
- Never expose
jaza.consumeor secret-backed routes to the device as a public “debit” API without your own auth - UI gates (
JazaActionButton) are not authorization — always consume on the server
Next
- Top-up — session-minted MoMo checkout
- Gating actions — ActionButton + host consume
- Authentication — keys and tokens