使用 joi-password-complexity 时无法混合不同版本的 joi 模式错误
Cannot mix different versions of joi schemas error when using joi-password-complexity
我在将 joi-password-complexity 集成到我的 Joi 验证逻辑时遇到了一些问题。我得到的错误是 Cannot mix different versions of joi schemas
。我需要更改什么?
schemasShared.js
const Joi = require('@hapi/joi');
const JoiPasswordComplexity = require('joi-password-complexity');
const joiPasswordComplexityOptions = {
min: 10,
max: 50,
lowerCase: 1,
upperCase: 1,
numeric: 1,
symbol: 1,
requirementCount: 4,
};
const passwordLogin = new JoiPasswordComplexity(
joiPasswordComplexityOptions
);
module.exports = {
passwordLogin
};
auth.schemas.js
const Joi = require('@hapi/joi');
const schemasShared = require('../../utils/schemasShared');
const authRequirements = {
password: schemasShared.passwordLogin,
}
const authSchemas = {
loginBody: Joi.object({ // The error points to this line, specifically to .object
password: authRequirements
.password
.required(),
}),
}
我的版本:
- "@hapi/joi": "^16.1.7"
- "joi-password-complexity": "^3.1.0",
这在 v4.0 中已修复:joi-password-complexity。
v4.0 也支持 Joi v16/17
我在将 joi-password-complexity 集成到我的 Joi 验证逻辑时遇到了一些问题。我得到的错误是 Cannot mix different versions of joi schemas
。我需要更改什么?
schemasShared.js
const Joi = require('@hapi/joi');
const JoiPasswordComplexity = require('joi-password-complexity');
const joiPasswordComplexityOptions = {
min: 10,
max: 50,
lowerCase: 1,
upperCase: 1,
numeric: 1,
symbol: 1,
requirementCount: 4,
};
const passwordLogin = new JoiPasswordComplexity(
joiPasswordComplexityOptions
);
module.exports = {
passwordLogin
};
auth.schemas.js
const Joi = require('@hapi/joi');
const schemasShared = require('../../utils/schemasShared');
const authRequirements = {
password: schemasShared.passwordLogin,
}
const authSchemas = {
loginBody: Joi.object({ // The error points to this line, specifically to .object
password: authRequirements
.password
.required(),
}),
}
我的版本:
- "@hapi/joi": "^16.1.7"
- "joi-password-complexity": "^3.1.0",
这在 v4.0 中已修复:joi-password-complexity。
v4.0 也支持 Joi v16/17