使用joi-password-complexity时无法混合不同版本的joi模式错误

时间:2019-12-10 13:33:11

标签: node.js joi

在将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”,

1 个答案:

答案 0 :(得分:2)

此问题已在v4.0:joi-password-complexity中修复。

v4.0还支持Joi v16 / 17