From 00f9ec667f7de54d21b7bf32a27f9f09607b6d23 Mon Sep 17 00:00:00 2001 From: Amir Date: Sun, 31 Oct 2021 20:08:34 +0330 Subject: [PATCH] Add check for guards list from auth configuration --- src/Middleware/AuthRoles.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Middleware/AuthRoles.php b/src/Middleware/AuthRoles.php index f69a68c..c661912 100644 --- a/src/Middleware/AuthRoles.php +++ b/src/Middleware/AuthRoles.php @@ -20,15 +20,19 @@ class AuthRoles */ public function handle($request, Closure $next) { - - $guard = auth('api')->check() ? 'api' : ''; - throw_if(!auth($guard)->check(), UnauthenticatedException::notLoggedIn()); + $guards = collect(config('auth.guards')); + + $authGuard = $guards->keys()->filter(function($key) { + return auth($key)->check(); + })->first(); + + throw_if(!auth($authGuard)->check(), UnauthenticatedException::notLoggedIn()); $action = $request->route()->getActionname(); $name = $request->route()->getActionname(); - $role_id = auth($guard)->user()->role_id; + $role_id = auth($authGuard)->user()->role_id; $permission = Permission::where(function ($query)use ($action, $name){ $query->where('name', $name);