Skip to content

Commit

Permalink
Support for Laravel's model policy direct responses (#54)
Browse files Browse the repository at this point in the history
* Support for Laravel's model policy direct responses

* Apply fixes from StyleCI (#55)
  • Loading branch information
specialtactics authored Aug 19, 2022
1 parent f87852b commit 6b5f3a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Auth\Access\Gate;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* Trait AuthorizesUsersActionsAgainstModelsTrait
Expand Down Expand Up @@ -100,6 +101,13 @@ public function userCan($ability, $arguments = [])
return true;
}

// If not, check if we have a custom Response object, and if so, utilise it
// @var $response \Illuminate\Auth\Access\Response
$response = app(Gate::class)->forUser($user)->inspect($ability, $arguments);
if (! empty($response->message())) {
throw new HttpException($response->code(), $response->message());
}

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Features/JWTAuthenticationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getUser()
*/
protected function respondWithToken($token)
{
$tokenReponse = new \Stdclass;
$tokenReponse = new \stdClass;

$tokenReponse->jwt = $token;
$tokenReponse->token_type = 'bearer';
Expand Down

0 comments on commit 6b5f3a6

Please sign in to comment.