isAdmin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 9
c 5
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 3
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