'Pusher calls on authentication endpoint with empty request body?

I am a beginner on Pusher and have created a custom laravel authentication endpoint for private channel however $request->all() returns an empty array?

I can see that the payload being sent is below.

socket_id=16534.7004717&channel_name=private-user.3ZhVOw

Can someone help with this? below is my code.

app.js

Pusher.logToConsole = true;
  const pusher = new Pusher('pusher_key', {
    cluster: "ap1",
    authEndpoint: `${protocol}//api.${host}/api/broadcast/auth`,
    auth: {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${accessToken}`
      }
    }
  });
  const channel = pusher.subscribe(`private-user.1234`);
  channel.bind('my-event', (data) => {
    console.log(data);
  })

api.php

Route::match(['get', 'post'],'/broadcast/auth', 'Auth\BroadcastController@authenticateBroadcast');

BroadcastController.php

public function authenticateBroadcast(Request $request) {
        $pusher = new Pusher(
            config('broadcasting.connections.pusher.key'),
            config('broadcasting.connections.pusher.secret'),
            config('broadcasting.connections.pusher.app_id'),
            config('broadcasting.connections.pusher.options')
        );
       Log::info($request->all());
        return $pusher->socket_auth($request->channel_name, $request->socket_id);
    }

Devtools Network Tab enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source