diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 51c87f4..b90bf34 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -7,6 +7,7 @@ use Throwable; use Illuminate\Http\{Request, Response}; use Illuminate\Validation\ValidationException; use Slowlyo\OwlAdmin\Exceptions\AdminException; +use Illuminate\Auth\AuthenticationException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class Handler extends ExceptionHandler @@ -49,4 +50,11 @@ class Handler extends ExceptionHandler 'errors' => $exception->errors(), ], $exception->status); } + + protected function unauthenticated($request, AuthenticationException $exception) + { + return $this->shouldReturnJson($request, $exception) + ? response()->json(['code' => Response::HTTP_UNAUTHORIZED, 'message' => $exception->getMessage()], 401) + : redirect()->guest($exception->redirectTo() ?? route('login')); + } }