无法对Laravel Echo客户端进行身份验证
我看到这个问题已经被问了很多次,但是没有一个答案是有效的,所以我请求帮助和一些见解 我正在使用laravel echo和redis来广播活动。我的laravel echo服务器运行良好,redis运行良好 重新加载网页时,在laravel echo服务器终端中出现以下错误:无法对Laravel Echo客户端进行身份验证,laravel,laravel-echo,Laravel,Laravel Echo,我看到这个问题已经被问了很多次,但是没有一个答案是有效的,所以我请求帮助和一些见解 我正在使用laravel echo和redis来广播活动。我的laravel echo服务器运行良好,redis运行良好 重新加载网页时,在laravel echo服务器终端中出现以下错误: ⚠ [4:49:19 PM] - qg4WSWl5YusQY8hJAAAA could not be authenticated to private-test-channel.1 {"error":"Unauthentic
⚠ [4:49:19 PM] - qg4WSWl5YusQY8hJAAAA could not be authenticated to private-test-channel.1
{"error":"Unauthenticated."}
Client can not be authenticated, got HTTP status 401
我一直在做这件事,但没有什么能帮上忙
这是我的app.js
import Echo from "laravel-echo";
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
window.Echo.private('test-channel.{{Auth::user()->id}}')
.listen('EventName', function(event) {
console.log('data', event);
});
这是我的echo.js
import Echo from "laravel-echo";
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
window.Echo.private('test-channel.{{Auth::user()->id}}')
.listen('EventName', function(event) {
console.log('data', event);
});
我的广播服务提供商
public function boot()
{
//broadcast routes middleware
Broadcast::routes(['middleware' => ['auth', 'web']]);
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
//require all base channels
require base_path('routes/channels.php');
}
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
这是我的larave-echo-server.json
{
"authHost": "http://127.0.0.1:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "570453f474365cc8",
"key": "4baec74e662696009e7857e49d3364c4"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "127.0.0.1",
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": ""
}
当我触发我的事件时,我会在控制台中获取该事件,但由于某种原因,无法对用户进行身份验证,我无法找出原因。您是否在routes/channels.php中看到了权限 这是解释的链接: 我看到您已将
BroadcastServiceProvider
public function boot()
{
//broadcast routes middleware
Broadcast::routes(['middleware' => ['auth', 'web']]);
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
//require all base channels
require base_path('routes/channels.php');
}
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
但在routes/channels.php中,默认命令是:
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
可能是产生了一些冲突或问题您是否删除了BroadcastServiceProvider中的代码,并将权限放入channels.php中,如文档所示?你能用channels.php编辑吗?您是否已按照文档所述导入?是否可以使用channels.php和BroadcastServiceProvider编辑问题,而不使用channel?我认为问题在于广播::频道()的名称。它应该是:Broadcast::channel(testchannel.{id})得到了任何解决方案,我也面临着同样的问题