Explorar el Código

Merge branch 'develop' of http://git.caihongxingqiu.net/rainbow/config-service into develop

caihongxingqiu hace 6 años
padre
commit
94729b7280
Se han modificado 2 ficheros con 8 adiciones y 9 borrados
  1. 0 9
      app/Exceptions/Handler.php
  2. 8 0
      app/Http/Middleware/JwtAuthMiddleware.php

+ 0 - 9
app/Exceptions/Handler.php

@@ -8,8 +8,6 @@ use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Database\Eloquent\ModelNotFoundException;
 use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
 use Symfony\Component\HttpKernel\Exception\HttpException;
-use Tymon\JWTAuth\Exceptions\JWTException;
-use Tymon\JWTAuth\Exceptions\TokenInvalidException;
 
 class Handler extends ExceptionHandler
 {
@@ -47,13 +45,6 @@ class Handler extends ExceptionHandler
      */
     public function render($request, Exception $exception)
     {
-        if($exception instanceof JWTException){
-            $error = [
-                'message' => $exception->getMessage(),
-                'code' => 401,
-            ];
-            return response()->json($error)->setStatusCode(401);
-        }
         return parent::render($request, $exception);
     }
 }

+ 8 - 0
app/Http/Middleware/JwtAuthMiddleware.php

@@ -3,6 +3,7 @@
 namespace App\Http\Middleware;
 
 use Closure;
+use function FastRoute\TestFixtures\empty_options_cached;
 use Tymon\JWTAuth\Exceptions\JWTException;
 use Tymon\JWTAuth\Exceptions\TokenExpiredException;
 use Tymon\JWTAuth\Exceptions\TokenInvalidException;
@@ -22,6 +23,13 @@ class JwtAuthMiddleware
 
         try {
             $token = JWTAuth::getToken();
+            if(empty($token)){
+                $error = [
+                    'message' => 'token is required',
+                    'code' => 401,
+                ];
+                return response()->json($error);
+            }
             $data = JWTAuth::decode($token);
             if ($data->sign !== md5($data->uid . env('JWT_SECRET'))) {
                 $error = [