Laravel Echo + VueJS broadcast/auth 问题
Laravel Echo + VueJS broadcast/auth problem
我正在使用 Laravel Echo 和推送器作为我的服务器。它已经在 public 个频道上运行。
这是我的 laravel 回声侦听器 image link
的照片
现在我的问题是当我使用 PrivateChannel 并在私人频道中收听时弹出此错误:
POST http://localhost:3000/broadcasting/auth 500(内部服务器错误)
在 console/network 选项卡的错误中,它显示路线 [登录] 未定义。
这是console/networkhttps://i.stack.imgur.com/fnAGp.png
里面的一张图片
我做过的事情:
-Uncommented App\Providers\BroadcastServiceProvider::class in config/app.php
-Added Broadcast::routes(['middleware' => ['auth:api']]); in BroadcastServiceProvider.php
-Used Echo.private('channel-name') instead of Echo.channel('channel-name') for listening to private channels
-Added authEndpoint : 'http://localhost:3000/broadcasting/auth' to bootstrap.js(This is where my Echo options are)
-Added a channel(probably the private channel) in my channels.php (here is a photo)
-Added csrf token meta tag in my main blade
在推送服务器中,它在触发时接收事件,这里是
picture of the event successfully fired.
所以问题是当我收听私人频道时会弹出错误,但当收听 public 频道时一切正常,我不太确定如何评估这个问题。
您必须像下面这样通过推送器请求传递身份验证 header。
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'APP_KEY',
authEndpoint: '/broadcasting/auth'
auth: {
headers: {
'Authorization': 'Bearer your_api_Toke',
'X-CSRF-Token': "CSRF_TOKEN"
}
}
});
更多详情:
https://github.com/laravel/echo/issues/26
Laravel Echo not using Auth Headers
我正在使用 Laravel Echo 和推送器作为我的服务器。它已经在 public 个频道上运行。
这是我的 laravel 回声侦听器 image link
的照片现在我的问题是当我使用 PrivateChannel 并在私人频道中收听时弹出此错误:
POST http://localhost:3000/broadcasting/auth 500(内部服务器错误)
在 console/network 选项卡的错误中,它显示路线 [登录] 未定义。
这是console/networkhttps://i.stack.imgur.com/fnAGp.png
里面的一张图片我做过的事情:
-Uncommented App\Providers\BroadcastServiceProvider::class in config/app.php
-Added Broadcast::routes(['middleware' => ['auth:api']]); in BroadcastServiceProvider.php
-Used Echo.private('channel-name') instead of Echo.channel('channel-name') for listening to private channels
-Added authEndpoint : 'http://localhost:3000/broadcasting/auth' to bootstrap.js(This is where my Echo options are)
-Added a channel(probably the private channel) in my channels.php (here is a photo)
-Added csrf token meta tag in my main blade
在推送服务器中,它在触发时接收事件,这里是 picture of the event successfully fired.
所以问题是当我收听私人频道时会弹出错误,但当收听 public 频道时一切正常,我不太确定如何评估这个问题。
您必须像下面这样通过推送器请求传递身份验证 header。
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'APP_KEY',
authEndpoint: '/broadcasting/auth'
auth: {
headers: {
'Authorization': 'Bearer your_api_Toke',
'X-CSRF-Token': "CSRF_TOKEN"
}
}
});
更多详情:
https://github.com/laravel/echo/issues/26
Laravel Echo not using Auth Headers