How to avoid console error 403 when backend not give return

292 views Asked by At

If I set my channel like this, I get console error 403.
note:: if ($user->status) isn't reg.

Broadcast::channel('using', function ($user) {
    if($user->status=='reg'){
       return $user->id;
    }
});

If I set my channel like this, everything is okay.

Broadcast::channel('using', function ($user) {
    if($user->status=='reg'){
        return $user->id;
    }else{
        return 'invalid';
    }
});

But I need to set my channel when $user->status isn't reg, I don't want to give any return.
Problem is if I don't give any return, I get console error 403.
Sorry for my english skill

1

There are 1 answers

1
Thân LƯƠNG Đình On

The data returned by the authorization callback will be made available to the presence channel event listeners in your JavaScript application. If the user is not authorized to join the presence channel, you should return false or null:

https://laravel.com/docs/8.x/broadcasting#authorizing-presence-channels

For $user->status isn't reg, you do not need to return data payload. You only return false or null.