我正在尝试使用laravel 5.8,laravel-echo-server,redis和socket.io构建实时通知系统
我广播了登录事件,我有两个类型的学生和教授
已验证的功能
protected function authenticated(Request $request, $user)
{
$event = new UserLoginEvent($user->id);
broadcast($event)->toOthers();
if ($user->isProf()) {
return redirect('/prof/dashboard');
}
return redirect('/etudiant/dashboard');
}
广播事件
public function __construct($user)
{
$this->user = $user;
}
public function broadcastOn()
{
return new PresenceChannel('login');
}
channel.php
Broadcast::channel('login', function ($user) {
if(Auth::check()){
return ['id'=>$user->id];
}
});
在教授控制器中,我使用了这些中间件
public function __construct()
{
$this->middleware(['auth','verified']);
$this->middleware('etudiant')->only(['search','rating']);
$this->middleware('prof')->only(['dashboard']);
$this->middleware('info')->except(['profil']);
}
教授中间件
public function handle($request, Closure $next)
{
if ( Auth::check() && Auth::user()->isProf() )
{
return $next($request);
}
return redirect('/');
}
在我使用的学生控制器中
public function __construct()
{
$this->middleware(['auth','verified','etudiant']);
}
学生中间件
public function handle($request, Closure $next)
{
if ( Auth::check() && !Auth::user()->isProf() )
{
return $next($request);
}
return redirect('/');
}
当我尝试与学生建立联系时,正常播放了该事件,但是在教授之间却出现了此错误
⚠ [2:52:13 PM] - uCUlo9fp3WNtRMgBAAAA could not be authenticated to presence-login
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="0;url='http://localhost:8000/login'" />
<title>Redirecting to http://localhost:8000/login</title>
</head>
<body>
Redirecting to <a href="http://localhost:8000/login">http://localhost:8000/login</a>.
</body>
</html>
Client can not be authenticated, got HTTP status 302