Pusher-js-auth is a client-side plugin designed to enhance the official `pusher-js` library by batching multiple private and presence channel authentication requests into a single HTTP call. This significantly improves performance and reduces network overhead when an application subscribes to numerous channels concurrently. The current stable version is 4.0.1, which is compatible exclusively with `pusher-js` versions 7.x and later. Older `pusher-js` versions (6.x and below) require the 3.x release of this plugin. While the project's release cadence is tied to major `pusher-js` updates, it provides a consistent solution for optimizing authentication workflows. Key differentiators include its seamless integration via the `authorizer` option in the `Pusher` client, and configurable `authDelay` for managing request timing. It requires a custom server-side authentication endpoint capable of processing batched channel names and returning a consolidated JSON response, which Pusher's server libraries can facilitate.
npm install pusher-js-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Pusher client with the `PusherBatchAuthorizer` and subscribe to multiple channels, showcasing how the plugin automatically batches authentication requests.
If using `pusher-js` v6 or older, downgrade this plugin to `pusher-js-auth` v3.x (`npm install pusher-js-auth@3`). For `pusher-js` v7+, ensure `pusher-js-auth` v4+ is used.
Implement or update your auth endpoint to parse `channel_name[0]`, `channel_name[1]`, etc., from incoming POST data. The endpoint must return a JSON object where keys are channel names and values are their respective authentication data or error statuses (e.g., `{'private-a': { 'auth': '...' }, 'private-c': { 'status': 403 }}`).Consider experimenting with `authDelay` if you observe unexpected authentication timing or wish to further optimize batching for extremely rapid channel subscriptions. For subscriptions within the same event loop, a value of 0 is typically sufficient.
Verify your server-side authentication endpoint's logic. Ensure it correctly parses the batched channel names from the request and returns a JSON object with valid authentication data or appropriate error statuses for each requested channel, following the `pusher-js-auth` expected output format.
Ensure `pusher-js-auth` is correctly installed (`npm install pusher-js-auth`) and imported (`import { PusherBatchAuthorizer } from 'pusher-js-auth';` or `const { PusherBatchAuthorizer } = require('pusher-js-auth');`). Additionally, confirm that your `pusher-js` version is 7 or higher if you are using `pusher-js-auth` v4+.