one of my application page is loading some content via ajax in my page (currently 2 requests, after document ready). Many times I receive for this ajax requests the status "401" with response "Unauthorized.". Sometimes on refresh the page (with F5) is it working, Some times ony one request is receiving 401 status. And less times i receive 500 (laravel is in this case using wrong database credentials, not from .env).
Can anyone help me with this issues?
Using Laravel 5.1.6
Thanks
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
return $next($request);
}