phplaravelpusher

/pusher/auth endpoint returning 404 in Laravel


I have built a Laravel app where I am trying to implement Web Sockets via Pusher.com (for the first time).

While I have got public channel subscriptions working fine, I am struggling getting private channels working correctly.

According to the laravel documentation you need to uncomment App\Providers\BroadcastServiceProvider::class in app.php config file which I have.

My channels.php has the following rule(s)

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

Broadcast::channel('private-queue.business.{business}', function ($user, Business $business) {
    // @todo: add real authentication
    return true;
});

Is there anything else I need to add to get /pusher/auth endpoint working?


Solution

  • As of Laravel 7.x, the Broadcasting endpoint is broadcasting/auth and not pusher/auth.

    I needed to update my JS like so to be able to define a custom auth endpoint:

    const pusher = new Pusher('{{ env('PUSHER_APP_KEY') }}', {
        cluster: '{{ env('PUSHER_APP_CLUSTER') }}',
        authEndpoint: '/broadcasting/auth',
        auth: {
            headers: {
                'X-CSRF-TOKEN': '{{ csrf_token() }}',
            }
        }
    });
    

    You will need to add the CSRF-TOKEN otherwise you will get Page Expired errors.