For 4 days I have been trying to connect to a private channel. Combined all the possible properties that I could find, but nothing solved the problem. A deeper understanding of the issue is needed.
I am creating an application using Laravel Sanctum, Nuxt.js, Nuxt-auth. I need to connect to a broadcasting private channel.
At first I tried to create a connection using the @nuxtjs/laravel-echo package.
After long attempts to configure the connection, I found that the PisherConnector instance is not even created if I set the authModule: true
(Public channels connect perfectly). Having discovered that this package is not actively supported and the fact that I do not have full access to connection management, I decided to abandon it.
Then I tried to set a connection using Laravel-echo and then directly through Pusher. Nothing works, I get either a 401 or 419 error.
I have a lot of questions and no answers.
- When do I need to use laravel-echo-server?
- When do I need to use pusher/pusher-php-server?
- In which case do I need to connect to
broadcasting/auth
, and in which toapi/broadcasting/auth
? My frontend runs onapi/login
, but I don't want to provide external access to my API. - I added
Broadcast::routes(['middleware' => ['auth: sanctum']])
to myBroadcastServiceProvider
and toroutes/api.php
too (for testing). I'm not sure here either.Broadcast::routes(['middleware' => ['auth: api']])
may be needed or leave the defaultBroadcast::routes()
? - What are the correct settings for configs:
config/cors.php
,config/broadcasting.php
,config/sanctum.php
,config/auth.php
? What key parameters can affect request validation? - Should I pass CSRF-TOKEN to headers? I have tried in different ways.
- When do I need to set the
encrypted:true
option? - What
middleware
should be present in theKernel
and what might get in the way?
If I set authEndpoint
to api/broadcasting/auth
I get 419 error (trying to pass csrf-token does not help). If I set authEndpoint
to broadcasting/auth
I get 401 error.
I do not provide examples of my code, since I tried all the options in all configs. I also tried to learn the documentation for my issue on the Laravel site, Pusher.js, looked at examples. Various examples mention some options but not others, and vice versa.
I would be glad to any advice.