joi syntax, adding db user builder key to cookie

This commit is contained in:
Martin McKeaveney 2021-04-14 13:22:57 +01:00
parent e8383653c1
commit 77c98009b8
2 changed files with 5 additions and 4 deletions

View File

@ -39,6 +39,7 @@ exports.authenticate = async function(username, password, done) {
if (await compare(password, dbUser.password)) { if (await compare(password, dbUser.password)) {
const payload = { const payload = {
userId: dbUser._id, userId: dbUser._id,
builder: dbUser.builder,
} }
const token = jwt.sign(payload, process.env.JWT_SECRET, { const token = jwt.sign(payload, process.env.JWT_SECRET, {

View File

@ -14,15 +14,15 @@ function buildUserSaveValidation() {
email: Joi.string(), email: Joi.string(),
password: Joi.string().allow(null, ""), password: Joi.string().allow(null, ""),
builder: Joi.object({ builder: Joi.object({
global: Joi.boolean().allow(undefined), global: Joi.boolean().optional(),
apps: Joi.array().allow(undefined), apps: Joi.array().optional(),
}).unknown(true).allow(undefined), }).unknown(true).optional(),
// maps appId -> roleId for the user // maps appId -> roleId for the user
roles: Joi.object() roles: Joi.object()
.pattern(/.*/, Joi.string()) .pattern(/.*/, Joi.string())
.required() .required()
.unknown(true) .unknown(true)
}).required().unknown(true).allow(undefined)) }).required().unknown(true).optional())
} }
router router