# Force email verification using Actions

**URL:** <https://community.auth0.com/t/force-email-verification-using-actions/76105>\
**Category:** Get Help\
**Tags:** actions, verification-email\
**Created:** [January 10, 2022, 3:29pm UTC](https://community.auth0.com/t/force-email-verification-using-actions/76105 "2022-01-10T15:29:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scronenberg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/scronenberg/32/34303_2.png) [@scronenberg](https://community.auth0.com/u/scronenberg)\
**Post date:** [January 10, 2022, 3:29pm UTC](https://community.auth0.com/t/force-email-verification-using-actions/76105/1 "2022-01-10T15:29:19Z")

</div>

Hi all,

I hope you have started this year well. I’m trying to create an Action that forces the user to verify her email before being able to authenticate.

In Rules, there is an already defined template that is the following:

```auto
function emailVerified(user, context, callback) {
  if (!user.email_verified) {
    return callback(
      new UnauthorizedError('Please verify your email before logging in.')
    );
  } else {
    return callback(null, user, context);
  }
}

```

What I want to do is basically migrate that same Rule to Actions, and what I was able to build is the following:

(Post User Registration Flow)

```auto
exports.onExecutePostUserRegistration = async (event) => {
   if (event.user.email_verified == false) {
     console.log ("Please verify your email before logging in.");
     return;
   }
};

```

This same thing is not giving me any result, any solution / advice?

Thanks a lot!

Santiago.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 11, 2022, 12:20am UTC](https://community.auth0.com/t/force-email-verification-using-actions/76105/3 "2022-01-11T00:20:43Z")

</div>

Hi @scronenberg,

Welcome to the Auth0 Community!

First, I would like to emphasize that Rules execute post-authentication. Therefore you will want to use the Post-Authentication Action in this scenario.

Having looked closely at your Action script, I noticed that you need to deny the user access if they have not verified their email instead of a console.log() statement. See below.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email_verified) {
    api.access.deny("Please verify your email before logging in.");
  }
};

```

Once this is complete, you will accomplish the same Force Email Verification Rule in Actions.

> **[Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)**
>
> Learn about the Actions Login Flow and the post-login Action trigger, which is executed after a user logs in and when a Refresh Token is requested.

Please let me know if there’s anything else I can do to help.

Thanks.

---

<div class="post-metadata">

**Author:** ![scronenberg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/scronenberg/32/34303_2.png) [@scronenberg](https://community.auth0.com/u/scronenberg)\
**Post date:** [January 11, 2022, 2:09pm UTC](https://community.auth0.com/t/force-email-verification-using-actions/76105/4 "2022-01-11T14:09:16Z")

</div>

Thank you so much!

Problem solved 🙂

---

<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:** [January 26, 2022, 2:09pm UTC](https://community.auth0.com/t/force-email-verification-using-actions/76105/5 "2022-01-26T14:09:30Z")

</div>

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