Completed
Push — master ( e792c1...df17fb )
by claudio
03:48
created
app/Http/Middleware/GetUserAndRefresh.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
     public function handle($request, \Closure $next, $custom = '')
22 22
     {
23 23
         $custom = $this->convertToArray($custom);
24
-        Debug::info('headers: '.implode('-',$request->all()));
25
-        if($token = $this->auth->setRequest($request)->getToken()) {
26
-        }else if ($this->auth->getUserModel()){
24
+        Debug::info('headers: '.implode('-', $request->all()));
25
+        if ($token = $this->auth->setRequest($request)->getToken()) {
26
+        } else if ($this->auth->getUserModel()) {
27 27
             $token = $this->auth->fromUser($this->auth->getUserModel(), $custom);
28
-        }else {
28
+        } else {
29 29
             return $this->respond('tymon.jwt.absent', 'token_not_provided', 401);
30 30
         }
31 31
 
32 32
         try {
33 33
             $user = $this->auth->authenticate($token, $custom);
34 34
         } catch (TokenExpiredException $e) {
35
-            return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [$e]);
36
-        } catch(InvalidClaimException $e) {
37
-            return $this->respond('tymon.jwt.invalid', 'claim_invalid', $e->getStatusCode(), [$e]);
35
+            return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [ $e ]);
36
+        } catch (InvalidClaimException $e) {
37
+            return $this->respond('tymon.jwt.invalid', 'claim_invalid', $e->getStatusCode(), [ $e ]);
38 38
         } catch (JWTException $e) {
39
-            return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]);
39
+            return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [ $e ]);
40 40
         }
41 41
 
42
-        if (! $user) {
42
+        if (!$user) {
43 43
             return $this->respond('tymon.jwt.user_not_found', 'user_not_found', 404);
44 44
         }
45 45
 
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
         try {
56 56
             $newToken = $this->auth->refresh($token, $custom);
57 57
         } catch (TokenExpiredException $e) {
58
-            return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [$e]);
58
+            return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [ $e ]);
59 59
         } catch (JWTException $e) {
60
-            return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]);
60
+            return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [ $e ]);
61 61
         }
62 62
 
63 63
         // send the refreshed token back to the client
64
-        $response->headers->set('Authorization', 'Bearer ' . $newToken);
64
+        $response->headers->set('Authorization', 'Bearer '.$newToken);
65 65
 
66 66
         return $response;
67 67
     }
Please login to merge, or discard this patch.