Level 63
You just have to implement authorization for your broadcasting.
import Cookies from 'js-cookie';
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
forceTLS: false,
encrypted: false,
channelAuthorization: {
endpoint: '/api/broadcasting/auth',
headers: {
'X-XSRF-TOKEN': Cookies.get('XSRF-TOKEN'),
Accept: 'application/json',
},
},
});
You also have to add a line in the bootstrap/app.php file.
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api_v1.php',
commands: __DIR__.'/../routes/console.php',
channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->statefulApi();
$middleware->alias([
'shared.datas' => SharedDatasMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions): void {
//
})
->withBroadcasting(
__DIR__.'/../routes/channels.php',
['prefix' => 'api', 'middleware' => ['api', 'auth:sanctum']],
)
->create();