File tree 1 file changed +15
-8
lines changed
1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,8 @@ userSchema.pre('save', function checkPassword(next) {
118
118
userSchema . pre ( 'save' , function checkApiKey ( next ) {
119
119
const user = this ;
120
120
if ( ! user . isModified ( 'apiKeys' ) ) {
121
- return next ( ) ;
121
+ next ( ) ;
122
+ return ;
122
123
}
123
124
124
125
let hasNew = false ;
@@ -129,22 +130,28 @@ userSchema.pre('save', function checkApiKey(next) {
129
130
if ( nextCalled ) return ;
130
131
if ( err ) {
131
132
nextCalled = true ;
132
- return next ( new Error ( err ) ) ; // ✅ Pass Error object
133
+ next ( err ) ;
134
+ return ;
133
135
}
134
- if ( -- pendingTasks === 0 ) {
136
+ pendingTasks -= 1 ;
137
+ if ( pendingTasks === 0 ) {
135
138
nextCalled = true ;
136
- return next ( ) ;
139
+ next ( ) ;
137
140
}
138
141
} ;
139
142
140
143
user . apiKeys . forEach ( ( k ) => {
141
144
if ( k . isNew ) {
142
145
hasNew = true ;
143
- pendingTasks ++ ;
146
+ pendingTasks += 1 ;
144
147
bcrypt . genSalt ( 10 , ( err , salt ) => {
145
- if ( err ) return done ( err ) ;
148
+ if ( err ) {
149
+ done ( err ) ;
150
+ }
146
151
bcrypt . hash ( k . hashedKey , salt , ( innerErr , hash ) => {
147
- if ( innerErr ) return done ( innerErr ) ;
152
+ if ( innerErr ) {
153
+ done ( innerErr ) ;
154
+ }
148
155
k . hashedKey = hash ;
149
156
done ( ) ;
150
157
} ) ;
@@ -153,7 +160,7 @@ userSchema.pre('save', function checkApiKey(next) {
153
160
} ) ;
154
161
155
162
if ( ! hasNew ) {
156
- return next ( ) ;
163
+ next ( ) ;
157
164
}
158
165
} ) ;
159
166
You can’t perform that action at this time.
0 commit comments