Laravel /broadcasting/auth 总是失败,并显示 403 错误
2022-08-30 19:01:02
我最近深入研究了Laravel 5.3的Laravel-Echo和Pusher组合。我已经成功地设置了公共频道,并转向了私人频道。我在 Laravel 从 /broadcasting/auth 路由返回 403 时遇到问题,无论我采取什么措施来尝试授权该操作(最多,包括使用简单的返回 true 语句)。谁能告诉我我做错了什么?
App/Providers/BroadcastService Providers.php:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return true;
});
}
}
resources/assets/js/booststrap.js:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'My-Key-Here'
});
window.Echo.private('App.User.1')
.notification((notification) => {
console.log(notification.type);
});
我可以在我的 Pusher 调试控制台中看到事件及其有效负载,一旦它到达身份验证路由,它就会失败。