# Authorization check method must return \`Authorization\\Policy\\ResultInterface\` or \`bool\`

**URL:** <https://discourse.cakephp.org/t/authorization-check-method-must-return-authorization-policy-resultinterface-or-bool/12233>\
**Category:** Need Help\
**Created:** [September 6, 2024, 4:16pm UTC](https://discourse.cakephp.org/t/authorization-check-method-must-return-authorization-policy-resultinterface-or-bool/12233 "2024-09-06T16:16:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Howan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/howan/32/3182_2.png) [@Howan](https://discourse.cakephp.org/u/Howan)\
**Post date:** [September 6, 2024, 4:16pm UTC](https://discourse.cakephp.org/t/authorization-check-method-must-return-authorization-policy-resultinterface-or-bool/12233/1 "2024-09-06T16:16:49Z")

</div>

Hey everyone,

I’m just trying to implement my authentication and it works well and i can only access the right houses.

I tried to break the authentication by changing the URL from this

```auto
http://localhost/hausundhof/houses/view/6

```

to this.

```auto
http://localhost/hausundhof/houses/view/7

```

Now i get the following error message.

> Authorization check method must return `Authorization\Policy\ResultInterface` or `bool`.

That seems like not the right Error.

```auto
# UserPolicy.php
<?php
declare(strict_types=1);

namespace App\Policy;

use App\Model\Entity\User;
use Authorization\IdentityInterface;

class UserPolicy
{
    public function canView(IdentityInterface $user, User $resource)
    {
        return $user->getIdentifier() === $resource->id;
    }
}

```

```auto
# UserController.php
 public function view($id = null)
    {
        $user = $this->Users->get($id, contain: ['Roles', 'Houses', 'TicketSnaps', 'Tickets']);
        $this->Authorization->authorize($user, 'view');
        $this->set(compact('user'));
    }

```

Mache ich da irgendetwas falsch??

Merci 🙏

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 6, 2024, 8:00pm UTC](https://discourse.cakephp.org/t/authorization-check-method-must-return-authorization-policy-resultinterface-or-bool/12233/2 "2024-09-06T20:00:13Z")

</div>

Why are you showing us code from your User controller and policy when it’s a House that you’re trying to access via your URL?

---

<div class="post-metadata">

**Author:** ![Howan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/howan/32/3182_2.png) [@Howan](https://discourse.cakephp.org/u/Howan)\
**Post date:** [September 7, 2024, 4:19pm UTC](https://discourse.cakephp.org/t/authorization-check-method-must-return-authorization-policy-resultinterface-or-bool/12233/3 "2024-09-07T16:19:26Z")

</div>

Hey Zuluru,

sorry for that, i was just completely lost becuse i tried to authorize the user with

```auto
$this->Authorization->authorize($house);

```

and then built the whole logic that the user sees only to his account connected houses what got very complicated. I just realized i can built that with.

```auto
$query = $this->Authorization->applyScope($query);

```

What a amazing way to write with so less code.

🙏
