2023-11-10 06:04:26 -08:00
|
|
|
import Container from 'typedi';
|
2024-09-12 09:07:18 -07:00
|
|
|
|
2023-08-23 19:59:16 -07:00
|
|
|
import config from '@/config';
|
2024-08-27 08:24:20 -07:00
|
|
|
import { UserRepository } from '@/databases/repositories/user.repository';
|
2023-08-23 19:59:16 -07:00
|
|
|
|
2024-09-12 09:07:18 -07:00
|
|
|
import { MFA_FEATURE_ENABLED } from './constants';
|
|
|
|
|
2023-08-23 19:59:16 -07:00
|
|
|
export const isMfaFeatureEnabled = () => config.get(MFA_FEATURE_ENABLED);
|
|
|
|
|
|
|
|
const isMfaFeatureDisabled = () => !isMfaFeatureEnabled();
|
|
|
|
|
|
|
|
const getUsersWithMfaEnabled = async () =>
|
2024-01-17 07:08:50 -08:00
|
|
|
await Container.get(UserRepository).count({ where: { mfaEnabled: true } });
|
2023-08-23 19:59:16 -07:00
|
|
|
|
|
|
|
export const handleMfaDisable = async () => {
|
|
|
|
if (isMfaFeatureDisabled()) {
|
|
|
|
// check for users with MFA enabled, and if there are
|
|
|
|
// users, then keep the feature enabled
|
|
|
|
const users = await getUsersWithMfaEnabled();
|
|
|
|
if (users) {
|
|
|
|
config.set(MFA_FEATURE_ENABLED, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|