How to import custom `PreUserRegistrationError` class

How does one import the custom PreUserRegistrationError class for use in the pre-user registration hook? ESlint in the hook IDE throws a module undefined error.

I’m doing something similar to what’s shown in the sample script here:

Hey @happy.sisyphus, Welcome to the Auth0 Community!

To use the PreUserRegistrationError class , you don’t need any additional import, the sample provided in the link shared by you should suffice. Based on the logic you are planning to implement you can directly use the class to throw the custom error.

This custom error functionality only works with New Login experience.


1 Like

Hmm. I’m still getting the ESLint error PreUserRegistrationError is not defined [no-undef], even though I changed to the New Login experience.

1 Like

Hey @happy.sisyphus, can you DM me your hook code to check?

1 Like

@sidharth.chaudhary When I tried to create the Pre Auth Hook, I was getting the ESLint error.

Below is a sample code:

module.exports = function (user, context, cb) {
  var response = {};

  response.user = user;

  // Add user or app metadata to the newly created user
  // response.user.user_metadata = { foo: 'bar' };
  // response.user.app_metadata = { vip: true, score: 7 };

  // Deny the user's registration and send a localized message to New Universal Login
  var denyRegistration = true;
  if (denyRegistration) {
       en: 'You are not allowed to register.',
       es: 'No tienes permitido registrarte.'
     const localizedMessage = LOCALIZED_MESSAGES[context.renderLanguage] || LOCALIZED_MESSAGES['en'];
     return cb(new PreUserRegistrationError('Denied user registration in Pre User Registration Hook', localizedMessage));

  cb(null, response);