2

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Could you try: Try this:

  • Uncomment App\Providers\BroadcastServiceProvider::class in config/app.php
  • Use php artisan config:cache
  • Use php artisan route:cache
  • Check new route broadcasting/auth with php artisan route:list

Source

1 Comment

Thanks, this helped me get closer to the answer. Its because Pusher by default tries /pusher/auth when Laravel by default uses broadcasting/auth

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.