# Custom authorization messages when policy check fails

**URL:** <https://discourse.cakephp.org/t/custom-authorization-messages-when-policy-check-fails/8961>\
**Category:** Need Help\
**Created:** [February 5, 2021, 6:05pm UTC](https://discourse.cakephp.org/t/custom-authorization-messages-when-policy-check-fails/8961 "2021-02-05T18:05:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![die7fox](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/die7fox/32/1970_2.png) [@die7fox](https://discourse.cakephp.org/u/die7fox)\
**Post date:** [February 5, 2021, 6:05pm UTC](https://discourse.cakephp.org/t/custom-authorization-messages-when-policy-check-fails/8961/1 "2021-02-05T18:05:30Z")

</div>

Hello, everyone. I apologize if this has been asked before, but I’m having a hard time finding anything on this subject.

I have the Authorization plugin loaded in my application, and it works fine, except for the messages the user gets back when they’re not authorized to do something. For example, only Site Admins are allowed to do anything with user accounts:

```
public function canAdd(IdentityInterface $user, User $resource)
    {
        // Site admins can add users
        $session = Router::getRequest()->getSession();
        $groups = $session->read('groups');
        return in_array('site_admin', $groups);
    }    

```

Calling `$this->Authorization->authorize($user)` in UsersController works, but how can I customize the error message an unauthorized user sees and redirect them somewhere else? There doesn’t seem to be an obvious way to do this.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [February 6, 2021, 2:20am UTC](https://discourse.cakephp.org/t/custom-authorization-messages-when-policy-check-fails/8961/2 "2021-02-06T02:20:30Z")

</div>

I normally just redirect to a friendly page I up set up with an explanation.

Or you could create a modal, with a message.

Several ways to achieve this.

Me I’d rather redirect to somewhere else.

---

<div class="post-metadata">

**Author:** ![mtbrandall](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mtbrandall](https://discourse.cakephp.org/u/mtbrandall)\
**Post date:** [February 6, 2021, 7:04am UTC](https://discourse.cakephp.org/t/custom-authorization-messages-when-policy-check-fails/8961/3 "2021-02-06T07:04:33Z")

</div>

This is what im trying to do but cannot find a way of making it work.
