Force email verification using Actions

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:

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)

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

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

Thanks a lot!


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.

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.

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


1 Like

Thank you so much!

Problem solved :slight_smile:

1 Like

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