Skip to content

Commit

Permalink
fix(mongoose): fix henri.user encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
reel committed Sep 26, 2018
1 parent a3bd585 commit 640d44a
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions packages/mongoose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,44 @@ class Mongoose {
*
* @param {any} schema The schema
* @param {any} model The model
* @param {any} user The user name
* @returns {object} The model
* @memberof Mongoose
*/
overload(schema, model, user) {
overload(schema, model) {
const { pen } = this.henri;

debug('overloading %s', model.globalId);

pen.info('mongoose', `user model`, model.globalId, `overloading...`);
schema.add({ email: { required: true, type: String } });
schema.add({ password: { required: true, type: String } });
schema.add({
email: {
required: true,
type: String,
},
});
schema.add({
password: {
required: true,
type: String,
},
});
const baseRole = (config.has('baseRole') && [config.get('baseRole')]) || [];

schema.add({ roles: { default: baseRole, type: Array } });
if (baseRole.length > 0) {
pen.info('mongoose', 'basic user role', baseRole);
} else {
pen.warn('mongoose', 'no basic user role. are you sure?');
}

schema.add({
roles: {
default: baseRole,
type: Array,
},
});
schema.pre('save', async function(next) {
if (!this.isModified('password')) return next();
this.password = await user.encrypt(this.password);
this.password = await henri.user.encrypt(this.password);
next();
});
schema.methods.hasRole = async function(roles = []) {
Expand Down Expand Up @@ -139,7 +159,9 @@ class Mongoose {
this.mongoose
.connect(
this.config.url || this.config.host,
{ useNewUrlParser: true }
{
useNewUrlParser: true,
}
)
.then(
() => {
Expand Down

0 comments on commit 640d44a

Please sign in to comment.