AuthenticateAndRenew   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 1
1
<?php
2
3
namespace Modules\Core\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard as GuardContract;
7
use Tymon\JWTAuth\JWTAuth;
8
use Tymon\JWTAuth\Providers\Auth\Illuminate;
9
10
class AuthenticateAndRenew extends BaseAuthenticate
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param \Closure                 $next
17
     * @param $guard
18
     *
19
     * @return mixed
20
     */
21
    public function handle($request, Closure $next, $guard)
22
    {
23
        app()->singleton('tymon.jwt.auth', function () use ($guard) {
24
            /** @var GuardContract $auth */
25
            $auth = auth($guard);
26
27
            return new JWTAuth(app('tymon.jwt.manager'), new Illuminate($auth), app('tymon.jwt.parser'));
28
        });
29
30
        $this->auth = app('tymon.jwt.auth');
31
32
        $this->authenticate($request);
33
34
        $response = $next($request);
35
36
        // Send the refreshed token back to the client.
37
        return $this->setAuthenticationHeader($response);
38
    }
39
}
40