I have a custom user App\Models\Client for which I want to broadcast notifications, Pusher works fine with public channels in my app but I can't get it to work with private channels.
So the problem is: /broadcasting/auth can't really authenticate the current user.
App\Providers\BroadcastServiceProvider.php:
public function boot()
{
Broadcast::routes(['middleware' => ['auth:client']]);
Broadcast::channel('App.Models.Client.{id}', function ($user, $id) {
return true;
});
}
bootstrap.js:
window.Pusher = require('pusher-js');
import Echo from "laravel-echo";
Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: '***********',
cluster: 'us2',
encrypted: true,
//auth: {
// headers: {
// 'X-CSRF-TOKEN': token.content // already set in the request by axios
// }
//},
});
if (Laravel.clientId) {
window.Echo.private(`App.Models.Client.${Laravel.clientId}`)
.notification((notification) => {
console.log(notification);
});
}
I'm using the normal Laravel session, so no auth:api middleware or Authorization header needed. the X-CSRF-TOKEN is included with the request.
/broadcasting/auth request/response screenshot here
Any help would be much appreciated!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire