Skip to content

Commit abe1927

Browse files
authored
Merge pull request #3094 from processing/fix/undefined-password
Address Undefined Arguments Error in comparePassword
2 parents dd00029 + 8e6350c commit abe1927

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/models/user.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,16 @@ userSchema.set('toJSON', {
162162
userSchema.methods.comparePassword = async function comparePassword(
163163
candidatePassword
164164
) {
165-
return bcrypt.compare(candidatePassword, this.password);
165+
if (!this.password) {
166+
throw new Error('No password is set for this user.');
167+
}
168+
169+
try {
170+
return await bcrypt.compare(candidatePassword, this.password);
171+
} catch (error) {
172+
console.error('Password comparison failed!', error);
173+
return false;
174+
}
166175
};
167176

168177
/**

0 commit comments

Comments
 (0)