🔒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:
Marco Beretta 2024-06-06 19:23:11 +02:00 committed by GitHub
parent 5452d4c20c
commit b7fef6958b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 104 additions and 143 deletions

View file

@ -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,
};