# Render a custom error page from Rule

**URL:** <https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010>\
**Category:** Get Help\
**Tags:** error-page, rules, login\
**Created:** [April 13, 2021, 7:35am UTC](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010 "2021-04-13T07:35:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![narendravaghela](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/narendravaghela/32/28757_2.png) [@narendravaghela](https://community.auth0.com/u/narendravaghela)\
**Post date:** [April 13, 2021, 7:35am UTC](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010/1 "2021-04-13T07:35:12Z")

</div>

We have a custom rule setup that checks for the user’s email address against a predefined list of addresses. If a user is not available in that list, we are denying the login and throwing `UnauthorizedError`

We are using SSO + OAuth flow. Our main application redirects user to Auth0 login page with client id, callback URL and other required parameters.

The Rule is being executed correctly. But it redirects back to our callback URL with `error` and `error_description` query parameters. Instead of this, we want to render the default error page on Auth0 itself with custom error message.

Below is our sample rule code:

```auto
      if (!userHasAccess) {
        return callback(new UnauthorizedError('Email does not exist - Access denied.'));
      }

      callback(null, user, context);

```

How can we achieve the desired result?  
Is it mandatory to have a custom error page on somewhere else outside the Auth0?  
Can’t we render the default error page on Auth0 itself instead of redirect user back to callback URL?

Any help on this will be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 13, 2021, 1:29pm UTC](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010/3 "2021-04-13T13:29:32Z")

</div>

Hi @narendravaghela,

Welcome to the Community!

Unfortunately, because of the way that the OpenID Connect prescribes the login flow, Auth0 redirects the user to the callback URL with the error so that the application can display the error to the user.

The answer in this topic provides more info on the reason behind this behavior:

> [@Handling authorization\_error with hosted pages](https://community.auth0.com/t/handling-authorization-error-with-hosted-pages/9931/11):
>
> Hi, The way OIDC works is by redirecting users to a page where they are authenticated, and in case there is an unexpected error in the authentication process, forward it to the callback URL so the application can handle it. In the Auth0 server, rules are run after the user is authenticated, so it’s not possible for us to display errors in the login dialog itself (e.g. you could enter username/password, get prompted MFA, and then get an error from a rule), so those errors are sent to the applic…

There are some examples of how to implement the error handling in the [quickstart apps](https://auth0.com/docs/quickstarts/). For example, the React quickstart handles the error using:

```auto
const App = () => {
  const { isLoading, error } = useAuth0();

  if (error) {
    return <div>Oops... {error.message}</div>; // <-- This is where you'd render the custom error component/page
  }

  if (isLoading) {
    return <Loading />;
  }

  return (
    <Router history={history}>
      <div id="app" className="d-flex flex-column h-100">
        <NavBar />
        <Container className="flex-grow-1 mt-5">
          <Switch>
            <Route path="/" exact component={Home} />
            <Route path="/profile" component={Profile} />
            <Route path="/external-api" component={ExternalApi} />
          </Switch>
        </Container>
        <Footer />
      </div>
    </Router>
  );
};

```

---

<div class="post-metadata">

**Author:** ![narendravaghela](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/narendravaghela/32/28757_2.png) [@narendravaghela](https://community.auth0.com/u/narendravaghela)\
**Post date:** [April 13, 2021, 1:38pm UTC](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010/4 "2021-04-13T13:38:45Z")

</div>

Hello @stephanie.chamblee  
Thank you for a quick response. Now this clarifies the things.

---

<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:** [April 28, 2021, 1:39pm UTC](https://community.auth0.com/t/render-a-custom-error-page-from-rule/61010/5 "2021-04-28T13:39:36Z")

</div>

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