Hi, I’m working on implementing some client requirements for login credentials.
Is there a way to enforce a minimum of four characters in the attached email field?
I know this request is a bit silly, I’m not sure if you can even have an email that is less then four characters. Doing due diligence and asking though!!
I believe you can enforce this check using a rule. Verify the input fields in rule and validate according to your requirement and let the flow complete or raise error as per requirement.
Thanks for the pointers. Here’s what I ended up with. If you happen to take a look let me know if you notice any glaring issues, this is my first one of these hooks.
module.exports = function (user, context, cb) {
const response = {};
// Deny the user's registration and send a localized message to New Universal Login
if (user.email.length < 4) {
const LOCALIZED_MESSAGES = {
en: 'Email must be atleast four characters long.',
es: 'El correo electrónico debe tener al menos cuatro caracteres.'
};
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);
};
Actually, testing this code above did work in the hooks code editor however now when I try and create a new user I get the following error on the user create form after attempting to submit.
Error! Sandbox Error: Extensibility error
If I disable the pre-registration hook then the above error goes away.