Ad

Laravel Echo + VueJS Broadcast/auth Problem

- 1 answer

I'm using Laravel Echo and pusher as my server. It is working already on public channels.

Here is the photo of my laravel echo listener image link

Now my problem is when I use PrivateChannel and when I listen in the private channel this error pops out:

POST http://localhost:3000/broadcasting/auth 500 (Internal Server Error)

Inside the error in the console/network tab it says Route [login] not defined.

Here is an image inside the console/network https://i.stack.imgur.com/fnAGp.png

Things I have done:

-Uncommented App\Providers\BroadcastServiceProvider::class in config/app.php

-Added Broadcast::routes(['middleware' => ['auth:api']]); in BroadcastServiceProvider.php

-Used Echo.private('channel-name') instead of Echo.channel('channel-name') for listening to private channels

-Added authEndpoint : 'http://localhost:3000/broadcasting/auth' to bootstrap.js(This is where my Echo options are)

-Added a channel(probably the private channel) in my channels.php (here is a photo)

-Added csrf token meta tag in my main blade

In the pusher server it recieves the event when it is fired, here is a picture of the event successfully fired.

So the problem is when I listen to a private channel the error pops out but everything is okay when listening to a public channel, And I am not so sure how to assess with this problem.

Ad

Answer

You have to pass the auth header with the pusher request like below.

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'APP_KEY',
    authEndpoint: '/broadcasting/auth'
    auth: {
        headers: {
            'Authorization': 'Bearer your_api_Toke',
            'X-CSRF-Token': "CSRF_TOKEN"
         }
      }
    });

For more details:

https://github.com/laravel/echo/issues/26
Laravel Echo not using Auth Headers

Ad
source: stackoverflow.com
Ad