pusher-channels-flutter icon indicating copy to clipboard operation
pusher-channels-flutter copied to clipboard

Header data not receiving in backend

Open razaGetScope opened this issue 1 year ago • 2 comments

Hello guys,

We are using a presence channel and I need to some data via headers, but somehow its not reaching backend and not logging in backend logs as well, I tried sending both params and headers but none of them showed up in backend logs and due to this I am getting unauthenticated error.

This is my init code on app startup

 initPusher() async {
    if (pusher.connectionState != 'CONNECTED') {
      try {
        await pusher.init(
          apiKey: pusherApiKey,
          cluster: clusterKey,
          authParams: {
            'params': {'foo': 'bar'},
            'headers': {
              'x-token': 'xxxx',
              'x-token-user': 'xxx',
            }
          },
          onConnectionStateChange: (currentState, previousState) {
            var abc = currentState;
          },
          onSubscriptionSucceeded: (channelName, data) {
            var abc = data;
          },
          onSubscriptionError: (channelName, data) {
            var abc = data;
          },
          onError: (message, code, error) {
            var abc = message;
          },
          authEndpoint: endPoint,
        );

        await pusher.connect();
      } on Exception catch (e) {
        log('Error: $e');
      }
    }
  }

And below is my code when I try to subscribe to specific presence channel

  subscribePusher(
    String cId,
  ) async {
    var cName = channelName + cId;

    await pusher.subscribe(
        channelName: cName,
        onEvent: (onEvent) {
          var abc = onEvent;
        },
        onSubscriptionError: (message, code, error) {
          var abc = message;
        });
  }

  static pusherEventsHandler(dynamic data) {
    var abc = data;
  }
}

please let me know if I am missing something here

Thanks

razaGetScope avatar Jul 19 '23 21:07 razaGetScope

Any updates ?

Korefey avatar Jan 18 '24 14:01 Korefey

Passing headers with authParams only supports AJAX. You can use the onAuthorizor function to construct your own HTTP request, including providing the necessary headers. when specified, the onAuthorizor will be used to authorize any channel subscriptions.

benw-pusher avatar Mar 26 '24 15:03 benw-pusher