4 laravel
我正在尝试让我的应用程序连接到私人频道上的推送器。
但我在控制台中收到以下错误:
POST http://localhost:8000/broadcasting/auth 403(禁止)
应用程序.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('payment', require('./components/Payment.vue'));
Vue.component('form-ajax', require('./components/FormAjax.vue'));
Vue.component(
'passport-clients',
require('./components/passport/Clients.vue')
);
Vue.component(
'passport-authorized-clients',
require('./components/passport/AuthorizedClients.vue')
);
Vue.component(
'passport-personal-access-tokens',
require('./components/passport/PersonalAccessTokens.vue')
);
const app = new Vue({
el: '#app'
});
Echo.private(`articles.admin`)
.listen('ArticleEvent', function(e) {
console.log(e);
});
Run Code Online (Sandbox Code Playgroud)
错误的原因可能是什么以及如何解决它。
Laravel 版本 > 5.3 和 Pusher 时出现错误 403 /broadcasting/auth,您需要在resources/assets/js/bootstrap.js中更改代码
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your key',
cluster: 'your cluster',
encrypted: true,
auth: {
headers: {
Authorization: 'Bearer ' + YourTokenLogin
},
},
});
Run Code Online (Sandbox Code Playgroud)
并在app/Providers/BroadcastServiceProvider.php中更改
Broadcast::routes()
Run Code Online (Sandbox Code Playgroud)
和
Broadcast::routes(['middleware' => ['auth:api']]);
Run Code Online (Sandbox Code Playgroud)
或者
Broadcast::routes(['middleware' => ['jwt.auth']]); //if you use JWT
Run Code Online (Sandbox Code Playgroud)
它对我有用,希望对你有帮助。
归档时间: |
|
查看次数: |
11497 次 |
最近记录: |