# Any ‘good way’ to fail a login and keep user on the hosted login page?

**URL:** <https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990>\
**Category:** Get Help\
**Tags:** hosted-login-page, user-login, redirect, verify-email, redirect-rules\
**Created:** [December 15, 2017, 8:47am UTC](https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990 "2017-12-15T08:47:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Tillotson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joe_tillotson/32/12709_2.png) [@Joe\_Tillotson](https://community.auth0.com/u/Joe_Tillotson)\
**Post date:** [December 15, 2017, 8:47am UTC](https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990/1 "2017-12-15T08:47:06Z")

</div>

I am trying to implement this feature without requiring our clients to do any work:

“When a user attempts to login (and provides valid credentials) but they have _not_ yet verified their email, keep them on the Hosted Login Page (HLP) and present them with a validation message informing them that their email is not yet verified.”

It seems to me after researching this doco however, that this is not possible without significant (and likely very fragile) work:

> **[Redirect Users from Within Rules - Auth0 Docs](https://auth0.com/docs/customize/rules/redirect-users)**
>
> Learn how to customize authentication flows by redirecting users using rules. Example areas that can be customized include MFA, privacy policy acceptance, and gathering user data.

The problems are essentially:

1. what I really want to do is fail the login (easy - raise an UnauthorizedError in a rule), but _not_ return an error back to the client (hard)

2. in order to _not_ take the user back to the client, I am trying to use a redirect in a rule (using the doco above), but it is clearly geared towards completing a successful authentication, not re-trying a non-successful login

So without going into more detail about how it is possible but very hard & fragile to accomplish the above, is this scenario possible using an approach that does _not_ involve issuing a redirect within a rule, and does _not_ provide a (HTTP) response back to the client, so that the user stays on the HLP?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [December 27, 2017, 6:20pm UTC](https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990/2 "2017-12-27T18:20:24Z")

</div>

At this time, I’m not aware of any mechanism to achieve what you describe that would not try to resort to a redirect rule. In summary, a failed authentication transaction due to a raised error in a custom rule will trigger the response to the client application and this behavior is not configurable.

---

<div class="post-metadata">

**Author:** ![Joe\_Tillotson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joe_tillotson/32/12709_2.png) [@Joe\_Tillotson](https://community.auth0.com/u/Joe_Tillotson)\
**Post date:** [January 3, 2018, 6:43am UTC](https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990/3 "2018-01-03T06:43:49Z")

</div>

Thanks for the reply. We have essentially (so far) 2 scenarios where keeping the user on the HLP is what we would do if we were ‘building it all ourselves’. Here are these scenarios:

1. User attempts to login (using valid credentials) before having verified their email
2. User attempts to login using social provider account that does not have an email (e.g. FB)

IOW, we would greatly prefer a built in, simple mechanism for keeping the user on the HLP if/when we fail the login. Otherwise all N of our clients must implement “when I get this or that error, I take the user (back) to the HLP”

---

<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 2, 2018, 5:57am UTC](https://community.auth0.com/t/any-good-way-to-fail-a-login-and-keep-user-on-the-hosted-login-page/8990/4 "2018-03-02T05:57:49Z")

</div>


