Auth0 Home Blog Docs

Pre User Registration Hook not persisting user data

I’m trying to update the user email_verified status flag in a pre-registration hook to suppress sending the verification email for a certain connection type. I use multiple connections with different use cases. The pre-registration hook appears to update the user and returns the response(seen in logs), however, the data isn’t persisted to the user data. It just doesn’t update the email_verified flag.

Code snippet.

module.exports = function (user, context, cb) {
  var response = {};
  
  console.log("Email Verified Suppression: context DATA", context);
 
  response.user = user;
   
  const AdvocatesConnectionName = "Advocate";
  if (context.connection.name === AdvocatesConnectionName) {
     response.user.email_verified = true;
  }
  
    console.log("Email Verified Suppression EXIT: context DATA", response);
  
  cb(null, response);
};

Am I using this pre-hook wrong?

Side note: The Auth0 documentation is rich in articles but hard to follow connecting articles, contradictory and somewhat unclear.

Hi @stephen2,

I don’t think you will be able to prevent sending the verification email this way unfortunately.

I have seen this similarly implemented by turning off email verification entirely (this can be done in the email templates page of the dashboard), then using a post reg hook or a rule to send out email verification to the connections of your choosing. There are many ways to configure this, I would be happy to walk through them more granularly if necessary.

Hope this helps!

Thanks,
Dan

Also, if you’re able to point us to the unclear or contradictory documentation, we’d love to clean that up for you.

1 Like