# Actions - prevent login when email not verified

**URL:** <https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695>\
**Category:** Get Help\
**Created:** [August 27, 2021, 4:36pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695 "2021-08-27T16:36:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakub.sztukowski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakub.sztukowski/32/12805_2.png) [@jakub.sztukowski](https://community.auth0.com/u/jakub.sztukowski)\
**Post date:** [August 27, 2021, 4:36pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/1 "2021-08-27T16:36:58Z")

</div>

I would like to prevent login when user has an not verified email. I know you cannot show errors from rules / actions on the login page.  
For my tenant I have several different applications, I would not like to implement this event handler in each of them, so I have an idea to

1. build an independent webapp that will handle this event
2. use actions after login

I did a simple action (for simplicity, I omit the topic of token generation and verification):

exports.onExecutePostLogin = async (event, api) =\> {  
if (! event.user.email\_verified) {  
api.redirect.sendUserTo (“https://mywebapp\_for\_show\_error.com”);  
}  
};  
exports.onContinuePostLogin = async (event, api) =\> {  
if (! event.user.email\_verified) {  
// Here I would like the login process to start again  
}  
}

How can I get the flow to check if the email is verified?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [August 30, 2021, 2:00pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/2 "2021-08-30T14:00:45Z")

</div>

Hi @jakub.sztukowski

You are on the right track. I don’t understand your question, though.

Your app at mywebapp\_for\_show\_error.com can either be a simple error page, or it can say “Please check your email and verify it, once you have done that click the continue button”. And the continue button returns to the login flow (via the /continue endpoint).

John

---

<div class="post-metadata">

**Author:** ![jakub.sztukowski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakub.sztukowski/32/12805_2.png) [@jakub.sztukowski](https://community.auth0.com/u/jakub.sztukowski)\
**Post date:** [August 30, 2021, 2:24pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/3 "2021-08-30T14:24:35Z")

</div>

Hi, thank you for your response.  
Yes after user click continue button, I can go back to login flow (/continue) but …sometimes users click the continue button without clicking in verify email . I would like redirect again to mywebapp\_for\_show\_error.com becuse of event.user.email\_verified is still false. I can;t do this beause at exports.onContinuePostLogin it doesn’t work. Is there any way to start login flow again?  
Jakub

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [August 31, 2021, 1:07pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/4 "2021-08-31T13:07:33Z")

</div>

Hi @jakub.sztukowski

You cannot redirect a second time - each login flow is limited to a single redirect.

The easy answer is to fail the login with an unauthorized error, and tell the user to try again after they have verified their email.

The more user friendly but complex answer is to pull the user info before invoking the continue endpoint to make sure they have verified.

John

---

<div class="post-metadata">

**Author:** ![raul.volmar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raul.volmar/32/35955_2.png) [@raul.volmar](https://community.auth0.com/u/raul.volmar)\
**Post date:** [March 17, 2022, 10:48am UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/5 "2022-03-17T10:48:19Z")

</div>

Hi @jakub.sztukowski

I understand each login flow is limited to a single redirect.  
I have an issue where the user enters incorrect email and he will get into infinity loop,  
because there is no way to insert a new email and the same old email is used (which user is not able to confirm).

Do you have suggestion how can I improve this so that every time I redirect to /authorize the user has possibility to choose login or sign up again?

Raul

---

<div class="post-metadata">

**Author:** ![raul.volmar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raul.volmar/32/35955_2.png) [@raul.volmar](https://community.auth0.com/u/raul.volmar)\
**Post date:** [March 17, 2022, 12:21pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/6 "2022-03-17T12:21:08Z")

</div>

I actually figured out a way.

Whenever a user has NOT confirmed their email. I logged the user out from oauth0 session BEFORE showing them any response.

To achieve that I redirected user to /v2/logout endpoint and then showed user that they need to verify their email. This way the session is ended on auth0 side and the loop will not accrue.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 17, 2022, 1:02pm UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/7 "2022-03-17T13:02:30Z")

</div>

Perfect! Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 31, 2022, 11:09am UTC](https://community.auth0.com/t/actions-prevent-login-when-email-not-verified/68695/8 "2022-03-31T11:09:15Z")

</div>


