Skip to content

Commit a8dfd89

Browse files
authored
Merge pull request #13 from amiryousefi/enhance-guard-check
Enhance guard check
2 parents 3ff9932 + 00f9ec6 commit a8dfd89

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Middleware/AuthRoles.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ class AuthRoles
2020
*/
2121
public function handle($request, Closure $next)
2222
{
23-
24-
$guard = auth('api')->check() ? 'api' : '';
2523

26-
throw_if(!auth($guard)->check(), UnauthenticatedException::notLoggedIn());
24+
$guards = collect(config('auth.guards'));
25+
26+
$authGuard = $guards->keys()->filter(function($key) {
27+
return auth($key)->check();
28+
})->first();
29+
30+
throw_if(!auth($authGuard)->check(), UnauthenticatedException::notLoggedIn());
2731

2832
$action = $request->route()->getActionname();
2933
$name = $request->route()->getActionname();
3034

31-
$role_id = auth($guard)->user()->role_id;
35+
$role_id = auth($authGuard)->user()->role_id;
3236

3337
$permission = Permission::where(function ($query)use ($action, $name){
3438
$query->where('name', $name);

0 commit comments

Comments
 (0)