N
N
NikSIk312019-08-20 13:02:24
Laravel
NikSIk31, 2019-08-20 13:02:24

Laravel + pusher how to hide error?

How can I hide 403 forbidden error using lavarel and pusher? The situation is this: I have users on my page who can receive messages, and others who cannot - this is checked in channel.php, for example

Broadcast::channel('post.{id}', function ($user, $id) {
  return *my expresion*;
});

and if it returns false , then users get a 403 error (in the browser console), otherwise everything works. And I get a page on which there may be users who have passed the test and have not passed to receive messages. But those who did not pass get an error - I would like to remove it.
Just in case, I'll throw off the important parts of the code:
BroadcastServiceProvider:
public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }

in the events folder, I have a NewComment event that implements ShouldBroadcast and has broadcastWith and broadcastOn:
public function broadcastOn()
    {
        return new PrivateChannel('post.' . $this->comment->post->id);
    }

on the front like this:
var channel = Echo.private('post.' + this.post.id);
            channel.listen('NewComment', (comment) => {
                console.log(comment);
            });

So:
I want any user visiting the page not to see the error. But only the specific one can use the channel. Now it works, but users who can't use the channel get a 403 error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Suha, 2019-08-20
@NikSIk31

How about checking if the user can listen to the channel or not even before you start listening to it and if they can't just not listen to the channel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question