Completed
Pull Request — master (#87)
by Cristian
08:06
created

BackpackAuthGuard::handle()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 9
Ratio 64.29 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 4
nop 2
dl 9
loc 14
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
7
class BackpackAuthGuard
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Closure                 $next
14
     *
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {
19 View Code Duplication
        if (config('backpack.base.separate_admin_session')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
            if (!\Auth::guard(config('backpack.base.admin_guard.name'))->check()) {
21
                if ($request->ajax() || $request->wantsJson()) {
22
                    return response(trans('backpack::base.unauthorized'), 401);
23
                }
24
25
                return redirect(config('backpack.base.route_prefix').'/login');
26
            }
27
        }
28
29
        return $next($request);
30
    }
31
}
32