I have been using Joi library for validation user inputs like this.
const Joi = require('joi');
const schema = Joi.object({
username: Joi.string()
.alphanum()
.min(3)
.max(30)
.required()
});
const validationResult = await schema.validateAsync({ username: 'a' }, { abortEarly: false, warnings: true });
This works fine, the problem is later in code I would want to use this validation again.
But the warning messages are still in the local context.
And if I input he { username: ‘ba’} the error message will still display that min length of “a” needs to be 3.
Do you know how can I use the schema object again, and strip the local warnings context.