mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-27 05:38:51 +01:00
refactor: update domain validation to use appConfig for allowed domains
This commit is contained in:
parent
677481dde6
commit
50bd6d3a02
8 changed files with 43 additions and 61 deletions
|
|
@ -1,10 +1,9 @@
|
|||
const { getCustomConfig } = require('~/server/services/Config');
|
||||
|
||||
/**
|
||||
* @param {string} email
|
||||
* @param {string[]} [allowedDomains]
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function isEmailDomainAllowed(email) {
|
||||
async function isEmailDomainAllowed(email, allowedDomains) {
|
||||
if (!email) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -15,14 +14,13 @@ async function isEmailDomainAllowed(email) {
|
|||
return false;
|
||||
}
|
||||
|
||||
const customConfig = await getCustomConfig();
|
||||
if (!customConfig) {
|
||||
if (!allowedDomains) {
|
||||
return true;
|
||||
} else if (!customConfig?.registration?.allowedDomains) {
|
||||
} else if (!Array.isArray(allowedDomains) || !allowedDomains.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return customConfig.registration.allowedDomains.includes(domain);
|
||||
return allowedDomains.includes(domain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,16 +63,14 @@ function normalizeDomain(domain) {
|
|||
/**
|
||||
* Checks if the given domain is allowed. If no restrictions are set, allows all domains.
|
||||
* @param {string} [domain]
|
||||
* @param {string[]} [allowedDomains]
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function isActionDomainAllowed(domain) {
|
||||
async function isActionDomainAllowed(domain, allowedDomains) {
|
||||
if (!domain || typeof domain !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const customConfig = await getCustomConfig();
|
||||
const allowedDomains = customConfig?.actions?.allowedDomains;
|
||||
|
||||
if (!Array.isArray(allowedDomains) || !allowedDomains.length) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue