From 93f7e111ba1167ece9ac25dcaab5d42c3b4a30ce Mon Sep 17 00:00:00 2001 From: Wisp X Date: Wed, 16 Feb 2022 15:52:00 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 11 +++++++++++ resources/views/common/api.blade.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 8e7fbd1b..de731466 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,11 +2,15 @@ namespace App\Exceptions; +use App\Http\Api; +use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Throwable; class Handler extends ExceptionHandler { + use Api; + /** * A list of the exception types that are not reported. * @@ -38,4 +42,11 @@ class Handler extends ExceptionHandler // }); } + + protected function unauthenticated($request, AuthenticationException $exception) + { + return $this->shouldReturnJson($request, $exception) + ? $this->error($exception->getMessage())->setStatusCode(401) + : redirect()->guest($exception->redirectTo() ?? route('login')); + } } diff --git a/resources/views/common/api.blade.php b/resources/views/common/api.blade.php index 3be2ee5d..39423b75 100644 --- a/resources/views/common/api.blade.php +++ b/resources/views/common/api.blade.php @@ -2,7 +2,7 @@
- api + {{ Auth::user()->tokens }}
@push('scripts')