使用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;
}
});
我该如何解决?
答案 0 :(得分: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
});
答案 1 :(得分:0)