Skip to content

Commit

Permalink
Merge pull request #13 from amiryousefi/enhance-guard-check
Browse files Browse the repository at this point in the history
Enhance guard check
  • Loading branch information
amiryousefi committed Oct 31, 2021
2 parents 3ff9932 + 00f9ec6 commit a8dfd89
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Middleware/AuthRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a8dfd89

Please sign in to comment.