当我尝试访问auth中间件下的任何路由时,都会重定向到登录路由。
Route::group(['middleware' => 'auth'], function () {
Route::get('area-cliente/resumo', 'AreaClienteController@resumo')->name('area_cliente_resumo');
});
这是我的身份验证中间件
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
if(Auth::guard('cliente')->guest())
{
return route('registrar');
}
return next($request);
}
}
我看不到重定向到登录路由的代码的位置,我也不知道为什么,因为用户显然是使用下面的代码登录的;
public function logar(Request $request) {
$credenciais = [
"email" => $request->email,
"senha" => $request->senha
];
$results = auth()->guard('cliente')->login(Cliente::find(1));
if(auth()->guard('cliente')->check()){
//I am able to echo the name of the user
//echo auth()->guard('cliente')->user()->name
return redirect()->route('home');
}
else{
echo "no";
}
}
我还尝试清除(删除所有功能)RedirectIfAuthenticated并验证中间件,但是应用程序的行为没有改变,我仍然被重定向到auth中间件下路由上的登录页面。