【问题标题】:Laravel echo admin channel authentication errorLaravel echo 管理员通道认证错误
【发布时间】:2018-06-23 07:12:04
【问题描述】:

我正在使用 Laravel 5.5 和 echo 作为管理面板, 主要守卫(网络)与 Admin 类有关, 我想获取的私人频道名称是 Admin.1 ,

问题是当我从

更改频道名称时
 Echo.private('App.User.' + this.userid)

Echo.private('App.Admin.' + this.userid) 

它给我这个错误

广播/身份验证 500(内部服务器错误)

我尝试的是:
我把这个

 Broadcast::routes(['middleware' => [ 'api', 'web','auth' ] ]);  

在 web.php 和 api.php 和 BroadcastServiceProvider.php 中,它似乎不起作用 我也试过这个解决方案 How to define or pass auth guard for broadcast authentication routes instead of default auth guard?

【问题讨论】:

    标签: laravel echo


    【解决方案1】:

    我通过以下方式解决了我的问题:
    将此添加到 BroadcastServiceProvider

    public function boot()
    {
        Broadcast::routes();
    
        require base_path('routes/channels.php');
    
         /*
         * for auth user channel
         */
          Broadcast::channel('App.Admin.{id}',function($user, $id){
              return (int) $user->id === (int) $id;
          });
    }
    

    【讨论】:

      【解决方案2】:

      在您的回声设置中,将 authEndpoint 设置为“广播/身份验证”。 这是遇到同样问题后对我有用的代码。

      new Echo({
          broadcaster: 'pusher',
          key: '{{env("PUSHER_APP_KEY")}}',
          cluster: 'us2',
          encrypted: true,
          authEndpoint: '{!! env("APP_URL") !!}/broadcasting/auth',
      });
      

      【讨论】:

      • @MohamedZayed 是的,只添加这一行和Broadcast::routes(['middleware' => [ 'web','auth' ] ]); 为我做了。
      • 不过,请确保您没有忘记添加 `{!! env("APP_URL") !!}' 如果您使用的是 pusher,请重新检查您的 APP_URL 和 Pusher 配置。
      • 我硬编码了路径而不是 APP_URL,但它不起作用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 2018-07-01
      相关资源
      最近更新 更多