pusher-channels-flutter
pusher-channels-flutter copied to clipboard
Header data not receiving in backend
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
Any updates ?
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.