I can't handle authorization (or something else) on private and presence channels. Regular channels work fine.
I am using latest Larvel and NuxtJS with Auth-next (v5). I am using Laravel Sanctum in SPA mode.
// nuxt.config.js
echo: {
broadcaster: 'pusher',
key: 'mykey',
authEndpoint: 'https://example.com/broadcasting/auth',
wsHost: 'example.com',
wssPort: 6001,
disableStats: true,
encrypted: true,
},
Page:
mounted() {
this.$echo.join("user.test").listen("UserTest", (e) => {
console.log("UserTest:");
console.log(e);
});
},
routes/channels.php
Broadcast::channel('user.test', function ($user) {
\Illuminate\Support\Facades\Log::debug('user test.'); -- log not working. As if it was not triggered at all
return true; -- not working
// return ['name' => $user->name]; -- not working
});
BroadcastServiceProvider.php
public function boot()
{
\Illuminate\Support\Facades\Log::debug('broadcast routes.'); -- works correctly
Broadcast::routes(['middleware' => ['auth:sanctum']]);
// Broadcast::routes();
require base_path('routes/channels.php');
}
Events/UserTest.php
class UserTest implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('channel-name');
\Illuminate\Support\Facades\Log::debug('PERSENCE.'); -- works correctly
return new PresenceChannel('user.test');
}
}
Maybe someone had a similar problem - I am asking for help or some tips.