Skip to content

Commit 1805975

Browse files
committed
fix(model): fix update bugs with mongoose and sequelize
1 parent df48188 commit 1805975

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Diff for: app/templates/server/api/user(auth)/user.model(mongooseModels).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var validatePresenceOf = function(value) {
102102
UserSchema
103103
.pre('save', function(next) {
104104
// Handle new/update passwords
105-
if (this.password) {
105+
if (this.isModified('password')) {
106106
if (!validatePresenceOf(this.password)<% if (filters.oauth) { %> && authTypes.indexOf(this.provider) === -1<% } %>) {
107107
next(new Error('Invalid password'));
108108
}

Diff for: app/templates/server/api/user(auth)/user.model(sequelizeModels).js

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ module.exports = function(sequelize, DataTypes) {
8989
},
9090
beforeUpdate: function(user, fields, fn) {
9191
if (user.changed('password')) {
92-
user.updatePassword(fn);
92+
return user.updatePassword(fn);
9393
}
94+
fn();
9495
}
9596
},
9697

0 commit comments

Comments
 (0)