I have been trying to solve this issue, but I have not found any solution. I have a Laravel 12 backend and a Vue 3 frontend, separate from each other. To subscribe to the private channel, I must authenticate with the backend. For that, I have used the endpoint: "broadcasting/auth," but it always returns an exception.
Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException
I have also tried to fix this, but no luck. I also added the middleware for Broadcast.
Broadcast::routes(['middleware' => ['auth:sanctum']]);
Also tried below
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('App.Models.User.*', function () {
return true;
});
Frontend pusher initialization
this.pusher = new Pusher(import.meta.env.VITE_PUSHER_KEY, {
cluster: import.meta.env.VITE_PUSHER_CLUSTER,
forceTLS: true,
authEndpoint: `${APP_URL}/broadcasting/auth`, // localhost:8000/broadcasting/auth
auth: {
headers: {
Authorization: BearerToken,
Accept: 'application/json',
},
},
})
it does make connection with the public channles but unable to do with the private