# How to Redirect to a Custom Error Page When Access is Denied

**URL:** <https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567>\
**Category:** Get Help\
**Tags:** classic-universal-login-experience, login-experience\
**Created:** [February 21, 2025, 6:50am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567 "2025-02-21T06:50:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KazukiKawashima](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kazukikawashima/32/73118_2.png) [@KazukiKawashima](https://community.auth0.com/u/KazukiKawashima)\
**Post date:** [February 21, 2025, 6:50am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/1 "2025-02-21T06:50:55Z")

</div>

We are testing whether we can implement single sign-on while restricting access to services based on each organization.  
As an implementation method, we use the Actions feature to restrict access to services for each organization.

Therefore, could you tell me how to redirect to the error page specified in Tenant Settings when access is denied in Actions?

Currently, we have specified a custom error page in Tenant Settings, but when access is denied in Actions, the service provider’s error page is displayed instead.

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [February 21, 2025, 7:39pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/3 "2025-02-21T19:39:03Z")

</div>

Hi @KazukiKawashima,

Welcome to the Auth0 Community!

This answer might be of help:

> [@Redirect Users After Denying Registration](https://community.auth0.com/t/redirect-users-after-denying-registration/92198):
>
> I’m looking for a way to redirect users back to an error page my organization hosts after preventing sign up/registration for a given user. I’m preventing access in a [Pre-User Registration Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow) action using api.access.deny. This is all well and good, but after this happens, we’d like to redirect them to an error page hosted on one of our domains/sites that can give them the reason why they failed to create an account and direct them as to how to proceed. The problem there is the only place in…

Unfortunately, denying access using Actions will only show a warning on the password input field, it won’t send the user to another page. But you should have some suggestions in the post above.

If you have any other question feel free to ask.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![KazukiKawashima](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kazukikawashima/32/73118_2.png) [@KazukiKawashima](https://community.auth0.com/u/KazukiKawashima)\
**Post date:** [February 25, 2025, 4:38am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/4 "2025-02-25T04:38:07Z")

</div>

After reviewing the article you shared, the following statement caught my attention:

> Or the second option is to use the Post-Login Action to deny the user access and then redirect them to your custom-hosted page. This is the approach I would recommend for your use case.

I am already using a Post-Login Flow action to deny access.  
However, while my action successfully redirects the user, it does not get recorded in the Monitoring Log.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.organization && event.organization.id == "xxxxxxx"){
    let enable = false;
    
    if (event.organization.metadata){
      let allowedapps = event.organization.metadata;
      enable = Object.values(allowedapps).includes(event.client.client_id);
    }

    if (!enable) {
          api.redirect.sendUserTo("https://example.com");
        }
    }
};

```

What I want to achieve is not only to deny access and perform the redirection but also to ensure that this event is logged in the Monitoring Log.

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [February 25, 2025, 4:28pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/5 "2025-02-25T16:28:00Z")

</div>

`api.redirect` suspends the code flow until the website redirects the user back to the authentication. Otherwise the code flow will not be resumed and the logging will never be triggered.

You can learn more about it here:

> **[Redirect with Actions](https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/redirect-with-actions#overview)**
>
> Learn how to use post-login Actions to redirect users before an authentication transaction is complete.

The best way to do it would be to use `api.access.deny` to send the user to the callback URL and in there you’ll need to process the error and redirect the user to the desired error page.

---

<div class="post-metadata">

**Author:** ![Mousom.Sarkar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mousom.sarkar/32/71440_2.png) [@Mousom.Sarkar](https://community.auth0.com/u/Mousom.Sarkar)\
**Post date:** [March 3, 2025, 3:46pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/6 "2025-03-03T15:46:33Z")

</div>

Hi team,  
I am also trying to using the same scenario.  
In my post login action, if any error happens, i am trying to catch that error and redirecting to a custom error page. however i am always getting “External Interaction Required.” message and it is not properly redirecting to the custom error page.

catch (error) {  
redirecting = true;  
logger.error(`post-login-mfa-handler::error::Making the customer to logout and redirect to the proper error ${error}`, {error, correlationId})  
logger.error(`post-login-mfa-handler::error::event.client.name ${event.client.name}`,{correlationId})  
const redirectPlaform = event.client.name === “Website” ? event.secrets.WEBSITE\_LOGOUT\_CALLBACK : event.secrets.APPS\_LOGOUT\_CALLBACK  
const redirectUrl = `https://${event.secrets.AUTH0_DOMAIN}/v2/logout?returnTo=${encodeURIComponent(redirectPlaform)}`;  
api.redirect.sendUserTo(redirectUrl);  
return;  
} finally {  
logger.error(`post-login-mfa-handler::error::Making the customer to logout and redirect:: Finally` )  
if (!redirecting) {  
flushSplunkLogs();  
logger.info(“Logs flushed successfully”);  
}  
}

is there anything I am missing?

Any quick guidance will be appreciated.

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [March 3, 2025, 5:51pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/7 "2025-03-03T17:51:26Z")

</div>

Hi @Mousom.Sarkar,

Welcome to the Auth0 Community.

As mentioned in this Knowledge Article, when an action is trying to redirect while in the middle of a silent authentication, this error will be thrown.

[https://community.auth0.com/t/error-external-interaction-required-appears-during-silent-authentication/106026](https://community.auth0.com/t/error-external-interaction-required-appears-during-silent-authentication/106026)

As stated above, the solution is to deny access, send the user to the callback URL and handle the error from there.

If you have any other questions feel free to ask us.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![Mousom.Sarkar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mousom.sarkar/32/71440_2.png) [@Mousom.Sarkar](https://community.auth0.com/u/Mousom.Sarkar)\
**Post date:** [March 4, 2025, 12:26am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/8 "2025-03-04T00:26:09Z")

</div>

Hi @vlad.murarasu ,  
Thank you so much.

Just to be clear from my side, here we are doing this.

- from post login action (there are two section - MFA and consent form), when we get any error and catch them,
- we should not use **api.redirect.sendUserTo(redirectUrl)**; but to use **api.access.deny** , right? please confirm.
- and then sends back to **Applications allowed callback** url
- if needed, Frontend can handle the error and show appropriate error message.  
is that the standard approach in this scenarios?  
Even though we have a custom error page - under - **Tenant Settings** → Error Pages. so when we will use that? we can not send or redirect to this custom error page?

Thank you,  
Mousom Sarkar

---

<div class="post-metadata">

**Author:** ![strahinja.ducic](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/strahinja.ducic/32/57889_2.png) [@strahinja.ducic](https://community.auth0.com/u/strahinja.ducic)\
**Post date:** [March 4, 2025, 9:32am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/9 "2025-03-04T09:32:58Z")

</div>

@vlad.murarasu Can you guys explain whole process step by step please. This is something what is not clear from documentation and I see that more and more guys have the same issue.  
When you said “send the user to the callback URL and handle the error from there”, how we can send them after api.access.deny and how we can send our error message on callback route. Can you please explain this in details? Thanks!!!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 18, 2025, 9:33am UTC](https://community.auth0.com/t/how-to-redirect-to-a-custom-error-page-when-access-is-denied/182567/10 "2025-03-18T09:33:50Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
