# Confirm email verification using post login action

**URL:** <https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [January 31, 2024, 9:49pm UTC](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219 "2024-01-31T21:49:46Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 30, 2024, 6:51pm UTC](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219/4 "2024-08-30T18:51:31Z")

</div>

Hey there @ywaka !

> [@ywaka](#):
>
> Currently, it appears that this action is also triggered when a user try to register an account. As soon as clicking the “Continue” button on the registration page, I gets error. I would like to apply this action only when the user login.

This is due to the fact that the user is being logged in after registration and hitting your `deny` logic - Are you looking to allow users to log in immediately following registration, but require email verification for all subsequent attempts? If so, you might consider an action similar to the following:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Check if the email is verified
  if (!event.user.email_verified) {
    // Check if it's the first login by checking the logins_count field
    const isFirstLogin = event.stats.logins_count === 1;

    // If it's not the first login and the email is not verified, deny access
    if (!isFirstLogin) {
      api.access.deny('Please verify your email before logging in again.');
    }
  }
  // Do nothing on the first login, allowing the user to proceed
};

```

> [@ywaka](#):
>
> Additionally, in cases where a user fails to login due to an unverified email, they are redirected to the base URL. Is there any way to display an error message on the login page instead of navigating to the base URL?  
> Furthermore, when I look into the error URL, I noticed that there is no error parameter.  
> The URL is something like this: [http://example.com/login?state=](http://example.com/login?state=)…

You can show an error message on the registration view of Universal Login, but not the login view:

> [@Auth0 Action api.access.deny is not displaying the provided error message to the user](https://community.auth0.com/t/auth0-action-api-access-deny-is-not-displaying-the-provided-error-message-to-the-user/92163/5):
>
> Thanks for following up on this and sharing your solution in another thread - To clarify (This is regarding New Universal Login), it is possible to show a custom error message to a user via a pre user registration action, using api.access.deny(reason, userMessage). It is not possible to show a similar custom error message via a post login action - Instead the reason provided in api.access.deny(reason) is included as a query param at the url the user is redirected back to.

---

_[View the full topic](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219)._
