# 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:** login-experience, new-universal-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:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ywaka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ywaka/32/50292_2.png) [@ywaka](https://community.auth0.com/u/ywaka)\
**Post date:** [January 31, 2024, 9:49pm UTC](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219/1 "2024-01-31T21:49:46Z")

</div>

Hi! I’m having issue with using post login action to confirm email verification when user login. 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.

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=)…

I would appreciate if you could help these issues. Thank you so much!

 ![Screenshot 2024-01-31 at 4.25.12 PM](https://global.discourse-cdn.com/auth0/original/3X/c/1/c1c8007fa94075ffc7eb25d5ab66fea7a0b11d44.png)

 ![Screenshot 2024-01-31 at 4.25.22 PM](https://global.discourse-cdn.com/auth0/original/3X/f/7/f7b612c4450860e9dc71b00e4e1c7ca9ee7f65b3.png)

---

<div class="post-metadata">

**Author:** ![gnwnzanf](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gnwnzanf/32/61481_2.png) [@gnwnzanf](https://community.auth0.com/u/gnwnzanf)\
**Post date:** [August 30, 2024, 4:50pm UTC](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219/2 "2024-08-30T16:50:09Z")

</div>

> [@ywaka](#):
>
> Hi! I’m having issue with using post login action to confirm email verification when user login. 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.
> 
> 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?

To address the issue with the post-login action triggering on user registration, you need to refine the condition under which the email verification check is applied. Ensure that the action is only executed for login attempts, not for account registrations. This might involve modifying the logic to check if the current action is a login request specifically, rather than a registration process.

---

<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.

---

<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:** [September 13, 2024, 6:51pm UTC](https://community.auth0.com/t/confirm-email-verification-using-post-login-action/126219/5 "2024-09-13T18:51:37Z")

</div>

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