mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* fix: add undefined password check in local user authentication * fix: edge case - issue deleting user when no conversations in deleteUserController * feat: Integrate Mailgun API for email sending functionality * fix: undefined SESSION_EXPIRY handling and add tests * fix: update import path for isEnabled utility in azureUtils.js to resolve circular dep.
31 lines
857 B
JavaScript
31 lines
857 B
JavaScript
const bcrypt = require('bcryptjs');
|
|
|
|
/**
|
|
* Compares the provided password with the user's password.
|
|
*
|
|
* @param {MongoUser} user - The user to compare the password for.
|
|
* @param {string} candidatePassword - The password to test against the user's password.
|
|
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating if the password matches.
|
|
*/
|
|
const comparePassword = async (user, candidatePassword) => {
|
|
if (!user) {
|
|
throw new Error('No user provided');
|
|
}
|
|
|
|
if (!user.password) {
|
|
throw new Error('No password, likely an email first registered via Social/OIDC login');
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
bcrypt.compare(candidatePassword, user.password, (err, isMatch) => {
|
|
if (err) {
|
|
reject(err);
|
|
}
|
|
resolve(isMatch);
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
comparePassword,
|
|
};
|