We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents dd00029 + 8e6350c commit abe1927Copy full SHA for abe1927
server/models/user.js
@@ -162,7 +162,16 @@ userSchema.set('toJSON', {
162
userSchema.methods.comparePassword = async function comparePassword(
163
candidatePassword
164
) {
165
- return bcrypt.compare(candidatePassword, this.password);
+ 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
175
};
176
177
/**
0 commit comments