Nozle
Entitlements

Real-Time Updates

WebSocket for live entitlement changes

Nozle uses WebSocket for real-time entitlement updates in the browser.

How it works:

  1. BillingProvider connects to WebSocket on mount
  2. Subscribes to channel: workspace:{workspaceId}:entitlements
  3. When entitlements change (plan upgrade, usage limit hit, feature toggled), Nozle publishes to the channel
  4. React hooks (useCan, usePlan) update automatically — no polling

Setup: Provide the WebSocket URL in BillingProvider:

<BillingProvider
  apiKey="pk_live_..."
  workspaceId="ws_abc123"
  centrifugoUrl="wss://rt.nozle.app/connection/websocket"
>
  {children}
</BillingProvider>

The SDK automatically:

  1. Requests a WebSocket auth token from GET /api/v1/auth/ws-token
  2. Connects to the WebSocket
  3. Subscribes to the entitlements channel
  4. Updates the billing store on incoming messages

Connection states: The BillingState tracks connection:

const { connectionState } = useBillingContext();
// 'connecting' | 'connected' | 'disconnected'

When updates are pushed:

  • Customer upgrades/downgrades plan
  • Usage counter crosses a limit threshold
  • Admin toggles a feature
  • Subscription is cancelled or expired

Without WebSocket: If centrifugoUrl is not provided, the React SDK falls back to REST-only mode. Hooks will fetch data on mount but won't receive live updates. For most apps, this is fine for non-critical UI. For real-time gates (e.g., locking a feature the moment a limit is hit), WebSocket mode is recommended.