mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔒refactor: social login and remove direct user model access in strategies (#2946)
* refactor: checking `ALLOW_SOCIAL_REGISTRATION` with `isEnabled` * feat: Add findUserByEmail function to UserService This commit adds a new function, , to the module. This function retrieves a user document from the database based on the provided email. It returns the user document if found, otherwise it returns null. If there is a problem during user retrieval, an error is thrown. * refactor: add socialLogin to remove repetitive code
This commit is contained in:
parent
5452d4c20c
commit
b7fef6958b
6 changed files with 104 additions and 143 deletions
|
|
@ -166,6 +166,23 @@ const checkUserKeyExpiry = (expiresAt, endpoint) => {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves a user document from the database based on the provided email.
|
||||
* @async
|
||||
* @param {string} email - The email of the user to find.
|
||||
* @returns {Promise<Object|null>} The user document if found, otherwise null.
|
||||
* @throws {Error} Throws an error if there is a problem during user retrieval.
|
||||
*/
|
||||
const findUserByEmail = async (email) => {
|
||||
try {
|
||||
const user = await User.findOne({ email });
|
||||
return user;
|
||||
} catch (error) {
|
||||
logger.error(`[findUserByEmail] Error occurred while finding user by email: ${email}`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
updateUserPluginsService,
|
||||
getUserKey,
|
||||
|
|
@ -174,4 +191,5 @@ module.exports = {
|
|||
updateUserKey,
|
||||
deleteUserKey,
|
||||
checkUserKeyExpiry,
|
||||
findUserByEmail,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue