我尝试在经过身份验证后删除重定向的经过身份验证的用户的默认Laravel行为。
我在LoginController.php
//protected $redirectTo = '/home';
并且还更改了AuthenticatesUsers
供应商文件以返回JSON而不是登录成功时的重定向:
protected function sendLoginResponse(Request $request)
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
/*return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());*/
return response()->json(['SUCCESS' => 'AUTHENTICATED'], 200);
}
但是当我成功登录时,我在Chrome网络标签中看到我收到错误,因为它试图将我重定向到/home
这是一个未定义的路由,导致错误并停止我的Laravel SPA
为什么即使在我发表评论并更改供应商文件后,Laravel仍继续指示我/home
?
答案 0 :(得分:4)
这是一个中间件问题。
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
//return redirect('/home');
}
return $next($request);
}
在,app/Http/Middleware/RedirectIfAuthenticated.php