mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-24 00:16:17 +00:00
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
GitNexus Index / index (push) Waiting to run
GitNexus Index / post-index (push) Blocked by required conditions
* fix: resolve group-scoped config overrides * test: fix endpoint config request mock typing * fix: keep remote agent preauth config tenant-scoped * test: align config scoping expectations * test: reproduce group endpoint override resolution
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { isEmailDomainAllowed } = require('@librechat/api');
|
|
const { getAppConfig } = require('~/server/services/Config');
|
|
|
|
/**
|
|
* Checks the domain's social login is allowed
|
|
*
|
|
* @async
|
|
* @function
|
|
* @param {Object} req - Express request object.
|
|
* @param {Object} res - Express response object.
|
|
* @param {Function} next - Next middleware function.
|
|
*
|
|
* @returns {Promise<void>} - Calls next middleware if the domain's email is allowed, otherwise redirects to login
|
|
*/
|
|
const checkDomainAllowed = async (req, res, next) => {
|
|
try {
|
|
const email = req?.user?.email;
|
|
const appConfig = await getAppConfig({
|
|
role: req?.user?.role,
|
|
userId: req?.user?.id,
|
|
tenantId: req?.user?.tenantId,
|
|
});
|
|
|
|
if (email && !isEmailDomainAllowed(email, appConfig?.registration?.allowedDomains)) {
|
|
logger.error(`[Social Login] [Social Login not allowed] [Email: ${email}]`);
|
|
res.redirect('/login');
|
|
return;
|
|
}
|
|
|
|
next();
|
|
} catch (error) {
|
|
logger.error('[checkDomainAllowed] Error checking domain:', error);
|
|
res.redirect('/login');
|
|
}
|
|
};
|
|
|
|
module.exports = checkDomainAllowed;
|