isAdmin::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 5
b 0
f 0
nc 3
nop 2
dl 0
loc 16
rs 10
1
<?php
2
3
namespace EasyPanel\Http\Middleware;
4
5
use EasyPanel\Support\Contract\AuthFacade;
6
use Closure;
7
8
class isAdmin
9
{
10
11
    public function handle($request, Closure $next)
12
    {
13
        $defaultGuard = config('easy_panel.auth_guard') ?? config('auth.defaults.guard');
14
        $redirectPath = config('easy_panel.redirect_unauthorized') ?? '/';
15
16
        auth()->shouldUse($defaultGuard);
17
18
        if(auth()->guest()){
19
            return redirect($redirectPath);
20
        }
21
22
        if(!AuthFacade::check(auth()->user()->id)){
23
            return redirect($redirectPath);
24
        }
25
26
        return $next($request);
27
    }
28
29
}
30