laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

Problem connecting to Private Channels

Open LJGrant opened this issue 3 years ago • 1 comments

Using Laravel 8 I've been trying to set up a private channel connection. I've gotten regular channels to connect just fine, but when I try to set up a private connection, I get a 500 error from my auth route with this error: Attempt to read property "key" on null {"exception":"[object] (ErrorException(code: 0): Attempt to read property \"key\" on null at /home/user/api/vendor/beyondcode/laravel-websockets/src/Dashboard/Http/Controllers/AuthenticateDashboard.php:27)

Connection setup:

 window.Echo = new Echo({
    broadcaster: "pusher",
    key: `${key}`,
    wsHost: `${host}`,
    wsPort: `${port}`,
    forceTLS: false,
    disableStats: true,
    encrypted: false,
    authEndpoint: `${authEndpoint}`,
    auth: {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    },
  });

...

window.Echo.private(`scaledata.${selectedScale.id}`).listen(
          "ScaleEvent",
          (e) => {
            console.log(e);
          }
        ); 

route setup:

Broadcast::routes();
Broadcast::channel('scaledata.{scaleId}', function ($user, $scaleId){
    return Scale::where('id', $scaleId)->exists();
});

I've tried using different versions of laravel-websockets and pusher/pusher-php-server but every time I get the same error. As far as I can tell I have everything configured correctly according to any documentation I can find but I can't find any solution for this for the life of me.

Any help would be highly appreciated

LJGrant avatar Dec 02 '21 17:12 LJGrant

https://github.com/beyondcode/laravel-websockets-demo/pull/22

erikn69 avatar Dec 03 '21 14:12 erikn69