我想验证根据用户类型编码的用户crendentiol。 目前,我正在使用以下验证架构。 我想验证userType是否为USER_TYPE_CUSTOMER,我想检查手机号码或电子邮件。我该如何更改以有条件地验证客户?
public schemaForCredentialAuth(): Joi.ObjectSchema {
return Joi.object({
authType: Joi.string().valid(AUTH_BY_CREDENTIAL).required(),
// internal or customer;
userType: Joi.string()
.valid(...getUserTypes())
.required(),
// mobile required for customer auth only
mobile: mobileNumberSchema
.when('userType', {is: USER_TYPE_CUSTOMER, then: Joi.required()}),
// email: required for internal user only
email: Joi.string().email({minDomainSegments: 2})
.when('userType', {is: USER_TYPE_INTERNAL, then: Joi.required()}),
password: Joi.string().min(5).max(30).required(),
});
}