我遇到401未经授权的错误,请帮助我!
Config / App.php
App\Providers\BroadcastServiceProvider::class,
BroadcastServiceProvider.php
Broadcast::routes(['middleware' => ['jwt.auth']]);
require base_path('routes/channels.php');
Bootstrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: '6f45c006cfba3fbc72c2',
cluster: 'ap1',
encrypted: true,
auth: {
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('authToken')
},
},
});
Channel.php
Broadcast::channel('OnChat', function ($user) {
if(JWTAuth::check()){
return $user;
}
});