alefesouza / laravel-vue-boilerplate

:elephant: A Laravel 8 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.
MIT License
543 stars 146 forks source link

Laravel Echo private channel #1

Closed ThunderPaul closed 6 years ago

ThunderPaul commented 6 years ago

Hi, I'm using Pusher as live notification system in your boilerplate, with public channel working fine, but I can't use private channel.

This is my code:

TheHeader.vue

(<any>window).Echo.private('App.User.' + this.userId)
    .listen('.job', (e) => {
        console.log(e.message);
    });

Event.php

public function broadcastOn()
    {
        return new PrivateChannel('App.User.'.$this->user->id);
    }

channel.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

When frontend call URL http://pusher.localhost/broadcasting/auth I have this error:

Symfony \ Component \ HttpKernel \ Exception \ AccessDeniedHttpException No message

image

Can you help me?

Thank you

alefesouza commented 6 years ago

Hello, I was able to reproduce this error, to fix it I just needed to uncomment "App\Providers\BroadcastServiceProvider::class" on the config/app.php file, and add the authorization header on the Echo options, something like this:

new Echo({
  // ...
  auth: {
    headers: {
      Authorization: 'Bearer ' + this.$auth.token(),
    },
  },
});

I will also push a version with Pusher and Laravel Echo already configured, thanks for the idea!

boyet007 commented 3 years ago

is this fix already?