Confirm email verification using post login action

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=

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

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.

1 Like

Hey there @ywaka !

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:

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
};


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