Auth0 Home Blog Docs

Pre Registration hook :Displaying wrong error message despite a correct response in runner

lock
hooks
pre-user-registratio

#1

I am using the following hook to prevent some users from signing up via lock.

module.exports = function (user, context, cb) {
  
  // Whitelisted domains
  const whitelist = 
    'example.com',
    'example1.com'
  ]; 

  const userHasAccess = whitelist.some(domain => {
    const emailSplit = user.email.split('@');
    return emailSplit[emailSplit.length - 1].toLowerCase() === domain;
  });

  if (!userHasAccess) {  
    return cb('You may not sign up with an email address using your current domain.');
  }

  const response = { user };
  return cb(null, response);
};

Runner and console show that it’s posting the 500 error. The runner displays the correct response and status code.

However I get:
“WE’RE SORRY, SOMETHING WENT WRONG WHEN ATTEMPTING TO SIGN UP.” instead of:
“You may not sign up with an email address using your current domain.” I am using lock on a hosted login page.

How can I fix this?


#2
 var token = createToken(
         configuration.CLIENT_ID,
         configuration.CLIENT_SECRET,
         configuration.ISSUER, {
           sub: user.user_id,
           email: user.email
         }
       );

#3

Hey Ariel,

Thanks for the reply,

I am unsure what to do with this new token at the moment I just have an unassigned createToken which causes an asynchronous uncaught exception.


#4