I tried to use laravel websocket with ionic; i used laravel-echo-ionic on my ionic project
in BroadcastServiceProvider.php
i commented the Broadcast::routes()
and added it to routes/api.php
Broadcast::routes(['middleware' => ['auth:api']]);
I used another model Customers
for my auth:api and use laravel passport.
in my channel.php
Broadcast::channel('App.Models.Customers.{id}', function ($customers, $id) {
return Auth::id() === $id; // i tried $customers->id to
}, ['guards' => ['api']]);
and in my ionic service provider i have
this.echo = new Echo({
broadcaster: 'pusher',
key: 'key', // .env
wsHost: 'localhost',
wsPort: 6001,
cluster: 'eu',
forceTLS: false,
disableStats: true,
authEndpoint: 'http://localhost/api/broadcasting/auth',
auth: {
headers: {
Authorization: 'Bearer ' + res.token
}
}
});
this.echo.private('App.Models.Customers.'+this.user_id).listen('.test', (data) => {
console.log(data)
})
when using public channel it work well, but when using private channel, the http://localhost/api/broadcasting/auth
request return error 403