Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header data not receiving in backend #120

Open
razaGetScope opened this issue Jul 19, 2023 · 2 comments
Open

Header data not receiving in backend #120

razaGetScope opened this issue Jul 19, 2023 · 2 comments

Comments

@razaGetScope
Copy link

razaGetScope commented Jul 19, 2023

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

@Korefey
Copy link

Korefey commented Jan 18, 2024

Any updates ?

@benw-pusher
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants