0

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

Michel Gisenaël
  • 211
  • 1
  • 2
  • 15

1 Answers1

0

I don't know if it's the proper way to do it with auth:api but i move my Broadcast::channel that used auth:api guard to my routes/api.php, so there i can access to my broadcast/auth within api middleware

Michel Gisenaël
  • 211
  • 1
  • 2
  • 15