Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ These variables are exposed to the client-side React application:
- Enable debug mode (mocks external services)
- Set to any value to enable

- **Config table: `white_email_domain` / `private_white_email_domain`**
- `white_email_domain`: Global email domain whitelist used when requesting email verification codes. Stored in the `config` table as JSON array string, for example: `["gmail.com"]`.
- `private_white_email_domain`: Higher-priority private email domain whitelist checked before `white_email_domain`. Also stored in the `config` table as JSON array string, for example: `["corp.example.com", "partner.org"]`.
- Configuration example in `config` table:
- `c_key = 'white_email_domain'`, `c_val = '["gmail.com"]'`
- `c_key = 'private_white_email_domain'`, `c_val = '["corp.example.com", "partner.org"]'`
- If an email domain is present in `private_white_email_domain`, it is accepted even if not listed in `white_email_domain`. If it is in neither list, the API responds with the same `error_api_email_domain` error and `white_email_domain` data as before.

## Running the Application

### Development Mode
Expand Down
16 changes: 13 additions & 3 deletions helpers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,21 @@ export function clearConfigCache(key) {
* Returns default ['gmail.com'] if config not found or parse fails
*/
export async function getWhiteEmailDomain() {
const domains = await getConfigValue('white_email_domain', ['gmail.com'], 300);
return Array.isArray(domains) ? domains : ['gmail.com'];
}

/**
* Get private white email domain list from config table
* Returns default [] if config not found or parse fails
*/
export async function getPrivateWhiteEmailDomain() {
const domains = await getConfigValue(
'white_email_domain',
['gmail.com'],
'private_white_email_domain',
[],
300
);
return Array.isArray(domains) ? domains : ['gmail.com'];
return Array.isArray(domains) ? domains : [];
}

export default {
Expand Down Expand Up @@ -268,6 +277,7 @@ export default {
findLastSendSmsByCountryNumber,
countTryNumber,
getWhiteEmailDomain,
getPrivateWhiteEmailDomain,
getConfigValue,
clearConfigCache,
};
17 changes: 10 additions & 7 deletions routes/apiHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ async function handleRequestEmailCode(req) {
}
// white list check
const emailDomain = email.split('@')[1];
const whiteEmailDomains = await database.getWhiteEmailDomain();
if (!whiteEmailDomains.includes(emailDomain)) {
throw new ApiError({
type: 'error_api_email_domain',
field: 'email',
data: { whiteEmailDomains },
});
const privateWhiteEmailDomains = await database.getPrivateWhiteEmailDomain();
if (!privateWhiteEmailDomains.includes(emailDomain)) {
const whiteEmailDomains = await database.getWhiteEmailDomain();
if (!whiteEmailDomains.includes(emailDomain)) {
throw new ApiError({
type: 'error_api_email_domain',
field: 'email',
data: { whiteEmailDomains },
});
}
}
// account creation policy check
const isEnoughPendingClaimedAccounts =
Expand Down