Entitlements
Real-Time Updates
WebSocket for live entitlement changes
Nozle uses WebSocket for real-time entitlement updates in the browser.
How it works:
- BillingProvider connects to WebSocket on mount
- Subscribes to channel: workspace:{workspaceId}:entitlements
- When entitlements change (plan upgrade, usage limit hit, feature toggled), Nozle publishes to the channel
- 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:
- Requests a WebSocket auth token from
GET /api/v1/auth/ws-token - Connects to the WebSocket
- Subscribes to the entitlements channel
- 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.