Skip to content

Commit 2745cd5

Browse files
authored
Merge pull request #10 from amiryousefi/add-api-guard-check
Add support for api guard
2 parents 07a2500 + 0f7b816 commit 2745cd5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Middleware/AuthRoles.php

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

24-
throw_if(!auth()->check(), UnauthenticatedException::notLoggedIn());
26+
throw_if(!auth($guard)->check(), UnauthenticatedException::notLoggedIn());
2527

2628
$action = $request->route()->getActionname();
2729
$name = $request->route()->getActionname();
2830

29-
$role_id = auth()->user()->role_id;
31+
$role_id = auth($guard)->user()->role_id;
3032

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

0 commit comments

Comments
 (0)