Pusher Auth value for subscription to private-channel has invalid format 'key:signature' (Laravel)

Pusher worked, but stopped. The .env settings are 100% correct. Please tell me how to debug this? Also, I tried to make new Puser app

Pusher : State changed : connecting -> connected with new socket ID 126791.4368004
pusher.min.js:8 Pusher : Event sent : {"event":"pusher:subscribe","data":{"auth":":88536630b30af895eb4ac1fcab4af7fcac1fbce3883074b00aa47cfc873c9362","channel":"private-user.1971"}}
pusher.min.js:8 Pusher : Event recd : {"event":"pusher:error","data":{"code":null,"message":"Auth value for subscription to private-user.1971 is invalid: should be of format 'key:signature'"}}
pusher.min.js:8 Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth value for subscription to private-user.1971 is invalid: should be of format 'key:signature'"}}}
PUSHER_APP_ID=902144
PUSHER_APP_KEY=0dd4fc93384fc94b5d6b
PUSHER_APP_SECRET=*****************
var pusher = new Pusher('0dd4fc93384fc94b5d6b', {
    cluster: 'eu',
    forceTLS: true,
    auth: {
        headers: {
             'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
        }
    }
});
class PusherController extends Controller
{
    public $pusher;

    public function __construct ()
    {
        $this->middleware('auth');
        $this->pusher = new Pusher(env('PUSHER_APP_KEY'), env('PUSHER_APP_SECRET'), env('PUSHER_APP_ID'));
    }

    public function auth(Request $request)
    {
        if (Auth::check()) {
            return $this->pusher->socket_auth($request->get('channel_name'), $request->get('socket_id'));
        } else {
            return Response::make('Forbidden', 403);
        }
    }
}

Broadcasting.php:

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => 'eu',
                'useTLS' => true
            ],
        ],

Everything worked, but at some point it stopped. I'm desperate :(

Upvotes: 0

Views: 830

Answers (1)

lagbox
lagbox

Reputation: 50491

Do not use env(...) outside of config files. Use the config(...) with reference to the file and key you need. Example: config('broadcasting.pusher.key')

If you cache the configuration the .env file does not get loaded which means env(...) returns null for everything.

Sounds like you cached your configuration. You can test this theory by clearing the configuration cache:

php artisan config:clear

If it starts working again that was your issue.

"If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null."

Laravel 5.8 Docs - Configuration - Configuration Caching

Upvotes: 1

Related Questions