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

Exception `ErrorException` thrown: `Undefined property: stdClass::$auth`

Open wrtisans opened this issue 3 years ago • 4 comments

I'm getting this error after upgraded to Laravel 9.0

Exception 'ErrorException' thrown: 'Undefined property: stdClass::$auth' 950546: exception 'ErrorException' thrown: 'Undefined property: stdClass::$auth'.

I'm using Laravel 9 with inertia and vue2

wrtisans avatar Mar 01 '22 10:03 wrtisans

I also get this error while trying to implement private channels.

Connection id 939293757.162424194 sending message {"event":"pusher:connection_established","data":"{\"socket_id\":\"939293757.162424194\",\"activity_timeout\":30}"}
qwersda: connection id 939293757.162424194 received message: {"event":"pusher:subscribe","data":{"channel":"private-new_tenant_registry.77Csfg6AYYeawtL5maeTcjEhnwQ2"}}.
Exception `ErrorException` thrown: `Undefined property: stdClass::$auth`
qwersda: exception `ErrorException` thrown: `Undefined property: stdClass::$auth`.

subooom avatar Mar 23 '22 09:03 subooom

  • laravel-websockets v1.13.1
  • laravel v9.6
  • pusher-php-server v7.0.2
  • PHP 8.1.4
  • default guard web
  • using passport as api authentication (auth:api)

same here any help?


websocket log

PUSHER_ID_1: connection id 961913920.471627343 received message: {"event":"pusher:subscribe","data":{"channel":"private-user.1"}}.
Exception `ErrorException` thrown: `Undefined property: stdClass::$auth`
PUSHER_ID_1: exception `ErrorException` thrown: `Undefined property: stdClass::$auth`.

.env

BROADCAST_DRIVER=pusher
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120

channels.php

image

event

image

caller

image

frontend nuxt v2.15

image

jasonnchann24 avatar Mar 31 '22 21:03 jasonnchann24

after reading the codebase and can't find any leads and decided to take a sleep

finally i got it working by following the version dep based on beyondcode/laravel-websockets-demo#22 , here's my final set up.

@wrtisans @subooom

Auth by Laravel Passport

composer

"php": "^8.0",
"beyondcode/laravel-websockets": "^1.13",
 "laravel/framework": "^9.0",
"pusher/pusher-php-server": "^7.0"

nuxt package.json

"laravel-echo": "^1.11.4",
"nuxt": "^2.9.0",
"pusher-js": "7.0.3",

BroadcastServiceProvider

public function boot()
    {
        // Broadcast::routes();
        Broadcast::routes(['middleware' => ['web', 'api', 'auth:api']]);

        require base_path('routes/channels.php');
    }

vue method


window.echo = new Echo({
        broadcaster: 'pusher',
        key: this.$config.WS_KEY, // key
        wsHost: this.$config.WS_HOST, // localhost
        wsPort: this.$config.WS_PORT, // 3003
        forceTLS: this.$config.WS_FORCE_TLS, // false
        disableStats: true,
        authEndpoint: `${this.$config.BASE_URL}/broadcasting/auth`,
        auth: {
          headers: {
            Authorization: `Bearer ${window.localStorage.getItem(
              'token_access'
            )}`,
          },
        },
      })

      window.echo
        .private('user.' + this.user.data.id)
        .listen('.testing_private', (e) => {
          console.log(e)
          this.privateMessages.push(e.message)
        })

jasonnchann24 avatar Apr 01 '22 10:04 jasonnchann24

I found a solution

Check some configuration

  1. Is BroadcastServiceProvider in config/app.php commented out or not
  2. Is BROADCAST_DRIVER in .env set to pusher correctly

Also, check the auth endpoint returning auth json or not, if it does, it should work! Auth JSON response format should like this: auth: "test_key:881d12c1ca9453bbe080782ddda74f2ec5582c852a0e7251eb40263b818f549d"

hsuan1117 avatar May 26 '22 15:05 hsuan1117