Passed
Pull Request — master (#2)
by ANTHONIUS
05:01
created

Authenticate::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the EOffice project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace EOffice\Auth\Middleware;
15
16
use Closure;
17
use Illuminate\Contracts\Auth\Factory as Auth;
18
use Illuminate\Http\Request;
19
use function response;
20
21
class Authenticate
22
{
23
    /**
24
     * The authentication guard factory instance.
25
     *
26
     * @var Auth
27
     */
28
    protected $auth;
29
30
    /**
31
     * Create a new middleware instance.
32
     *
33
     * @param Auth $auth
34
     *
35
     * @return void
36
     */
37
    public function __construct(Auth $auth)
38
    {
39
        $this->auth = $auth;
40
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param Request $request
46
     * @param \Closure                 $next
47
     * @param string|null              $guard
48
     *
49
     * @return mixed
50
     */
51
    public function handle($request, Closure $next, $guard = null)
52
    {
53
        if ($this->auth->guard($guard)->guest()) {
54
            return response('Unauthorized.', 401);
55
        }
56
57
        return $next($request);
58
    }
59
}
60