# Authorization Exception

**URL:** <https://discourse.cakephp.org/t/authorization-exception/11249>\
**Category:** Need Help\
**Created:** [June 1, 2023, 6:45pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249 "2023-06-01T18:45:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lamine](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@Lamine](https://discourse.cakephp.org/u/Lamine)\
**Post date:** [June 1, 2023, 6:45pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/1 "2023-06-01T18:45:41Z")

</div>

Hi there, I’m trying to redirect unauthorized actions to ‘/users/login’ URL but I get CakePHP error page instead.  
 ![Screenshot (32)](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/3/36c6a57456d2236d24e8af9ec79c86ff0d81857a.png)

 ![Screenshot (33)](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/a/ad280c07219cab7780d5d6ac2c140ca9bb443208.png)

---

<div class="post-metadata">

**Author:** ![synoza](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@synoza](https://discourse.cakephp.org/u/synoza)\
**Post date:** [June 2, 2023, 1:09pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/2 "2023-06-02T13:09:29Z")

</div>

Hello sir,

Is a bit weird to redirect to login page while your are connected. Resolve your conflict for redirect on a page that the user is allow to go connected.

---

<div class="post-metadata">

**Author:** ![Lamine](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@Lamine](https://discourse.cakephp.org/u/Lamine)\
**Post date:** [June 2, 2023, 2:35pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/3 "2023-06-02T14:35:14Z")

</div>

‘users/login’ its just to test how redirecting unauthorized action plays out same as ‘articles/index’, still waiting for your help on the issue.

---

<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:** [June 2, 2023, 3:48pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/4 "2023-06-02T15:48:16Z")

</div>

Have you got `use Authorization\Exception\ForbiddenException;` at the top of your `Application.php` file?

---

<div class="post-metadata">

**Author:** ![Lamine](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@Lamine](https://discourse.cakephp.org/u/Lamine)\
**Post date:** [June 2, 2023, 4:28pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/5 "2023-06-02T16:28:46Z")

</div>

Yes 👇

 ![Screenshot (34)](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/f/fe8b6f652d4c425c8efddbb3c23e2f371a81d158.png)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [June 2, 2023, 5:48pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/6 "2023-06-02T17:48:25Z")

</div>

@Lamine you have a small typo in your config. It should be `exceptions` not `exception`.

So like

```auto
'unauthorizedHandler' => [
    'className' => 'Authorization.Redirect',
    'url' => '/users',
    'queryParam' => 'redirectUrl',
    'exceptions' => [
        MissingIdentityException::class,
        ForbiddenException::class
    ]
]

```

Then your redirect should work.

---

<div class="post-metadata">

**Author:** ![Lamine](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@Lamine](https://discourse.cakephp.org/u/Lamine)\
**Post date:** [June 2, 2023, 7:29pm UTC](https://discourse.cakephp.org/t/authorization-exception/11249/7 "2023-06-02T19:29:53Z")

</div>

It working now, thanks.
