Files
Palmr/apps/server/src/modules/config/service.ts
Daniel Luiz Alves 765810e4e5 feat: implement disable password authentication configuration and validation
- Added a new configuration option for enabling/disabling password authentication.
- Implemented validation to prevent disabling password authentication if no other authentication providers are active.
- Updated authentication and login services to handle scenarios based on the password authentication setting.
- Enhanced the UI to reflect the password authentication status and provide user feedback accordingly.
- Added translations and error messages for better user experience across multiple languages.
2025-07-21 17:43:54 -03:00

63 lines
1.4 KiB
TypeScript

import { prisma } from "../../shared/prisma";
export class ConfigService {
async getValue(key: string): Promise<string> {
const config = await prisma.appConfig.findUnique({
where: { key },
});
if (!config) {
throw new Error(`Configuration ${key} not found`);
}
return config.value;
}
async setValue(key: string, value: string): Promise<void> {
await prisma.appConfig.update({
where: { key },
data: { value },
});
}
async validatePasswordAuthDisable(): Promise<boolean> {
const enabledProviders = await prisma.authProvider.findMany({
where: { enabled: true },
});
return enabledProviders.length > 0;
}
async validateAllProvidersDisable(): Promise<boolean> {
const passwordAuthEnabled = await this.getValue("passwordAuthEnabled");
return passwordAuthEnabled === "true";
}
async getGroupConfigs(group: string) {
const configs = await prisma.appConfig.findMany({
where: { group },
});
return configs.reduce((acc, curr) => {
let value: any = curr.value;
switch (curr.type) {
case "number":
value = Number(value);
break;
case "boolean":
value = value === "true";
break;
case "json":
value = JSON.parse(value);
break;
case "bigint":
value = BigInt(value);
break;
}
return { ...acc, [curr.key]: value };
}, {});
}
}