'Node.js joi - .number() fails to pas 0

I have this joi schema using .number() for a body parameter 'public'

contactSchema: Joi.object().keys({
    email: Joi.string().email().required(),
    public: Joi.number().required()
}),

If I allow the paremeter to be 0 in some instance ...

if(req.session.sessionEmail){
    var isPublic = 0;
  } else {
    var isPublic = 1;
  }

... joi says its invalid.

If I don't pass a 0 ... all is good?

if(req.session.sessionEmail){
    var isPublic = 2;
  } else {
    var isPublic = 1;
  }

Why does it fail in case of 0?

https://github.com/hapijs/joi/blob/master/API.md#number---inherits-from-any



Solution 1:[1]

Please try with

userId: joi.number().integer().min(1).required()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vaibhav kanmeriya