From 6c6a19a762cd618d888a96e27ce10c6b4b99cda9 Mon Sep 17 00:00:00 2001 From: manikandan_venkatesan Date: Thu, 26 Sep 2019 22:49:02 +0530 Subject: [PATCH] added password hashing in PUT method --- src/baseRoutes.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/baseRoutes.js b/src/baseRoutes.js index 4f1a776..fa0c963 100644 --- a/src/baseRoutes.js +++ b/src/baseRoutes.js @@ -177,8 +177,21 @@ const addBaseRoutes = (server, options) => { method: 'PUT', path: `/${modelName}/{id?}`, handler: async (request) => { - const data = Object.keys(request.payload).length > 0 ? request.payload : null; + let data = Object.keys(request.payload).length > 0 ? request.payload : null; const id = request.params.id ? encodeURIComponent(request.params.id) : null; + const { identityKey, passcodeKey, authModel } = authConfig; + if (authModel === modelName) { + if (request.payload[identityKey] && request.payload[passcodeKey]) { + const password = request.payload[authConfig.passcodeKey]; + const hash = await auth.hashPassword(password); + data = { + ...data, + [authConfig.passcodeKey]: hash, + }; + } else { + return Boom.badData('expected params not found'); + } + } if (data && id) { try { const model = sequelize.models[modelName];