Pusher:无法检索身份验证信息

问题描述 投票:1回答:2

使用Laravel echo,pusher和vuejs。

每当我尝试加入私人频道(自己用户的频道)时,都会收到此错误

"Pusher : Couldn't retrieve authentication info. 419Clients must be authenticated to join private or presence channels. See: https://pusher.com/docs/authenticating_users"

这是我加入频道的那一刻:

Echo.private('App.User.' + response.data.currentUser)
.listen('Event',(e)=>{});

response.data.currentUser确实正确包含了用户的id。

这是channel.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
    if (Auth::user()->id == (int) $id) {
        return ['STATUS' => 'OK'];
    } else {
        return false;
    }
});

我该怎么解决这个问题

php laravel pusher laravel-echo
2个回答
0
投票

我通过添加这个解决了这个问题

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({

    "authEndpoint": "/your-project-name/broadcasting/auth",
    broadcaster: 'pusher',
   key: '####################',
   cluster : "mt1",
   encrypted: true

});

0
投票

我有同样的问题,原来是我的服务器错过了PHP curl extension.

我先得到这个错误:

enter image description here

调用未定义的方法Pusher \ Pusher :: socket_auth()

然后我尝试安装:

composer require pusher/pusher-http-laravel

这导致系统错误中缺少PHP扩展卷曲。

enter image description here

安装php-curl之后:

sudo apt-get install php-curl

它修复了一切,现在正在工作。

© www.soinside.com 2019 - 2024. All rights reserved.