我有一个自定义用户App\Models\Client
,我想为其广播通知,Pusher在我的应用中可以与公共频道配合使用,但不能与私人频道一起使用。
因此问题是:/broadcasting/auth
无法真正验证当前用户。
App\Providers\BroadcastServiceProvider.php
:
public function boot()
{
Broadcast::routes(['middleware' => ['auth:client']]);
Broadcast::channel('App.Models.Client.{id}', function ($user, $id) {
return true;
});
}
bootstrap.js
:
window.Pusher = require('pusher-js');
import Echo from "laravel-echo";
Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: '***********',
cluster: 'us2',
encrypted: true,
//auth: {
// headers: {
// 'X-CSRF-TOKEN': token.content // already set in the request by axios
// }
//},
});
if (Laravel.clientId) {
window.Echo.private(`App.Models.Client.${Laravel.clientId}`)
.notification((notification) => {
console.log(notification);
});
}
我正在使用普通的Laravel会话,因此不需要auth:api
中间件或Authorization
标头。 X-CSRF-TOKEN
包含在请求中。
/broadcasting/auth
请求/响应屏幕截图here
任何帮助将不胜感激!
答案 0 :(得分:0)
Laravel 5.8
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: _controller,
decoration: InputDecoration(prefixText: "https://"),
),
RaisedButton(
child: Text("Submit"),
onPressed: () {
String text = _controller.text.toString();
if (!text.contains("https://")) {
text = "https://" + text;
}
// text here will always have https://
},
),
],
),
app/Providers/BroadcastServiceProvider.php
public function boot()
{
Broadcast::routes([ 'middleware' => [ 'web', 'isLoginFrontend']]);
require base_path('routes/channels.php');
}
routes/channels.php
答案 1 :(得分:0)
改成这样
Broadcast::routes(['middleware' => ['web', 'auth:client']]);
在
App\Providers\BroadcastServiceProvider.php:
我在我的项目中得到了这个。
答案 2 :(得分:0)
在except数组中添加/broadcasting/auth
(VerifyCsrfToken类)