mirror of
https://github.com/kyantech/Palmr.git
synced 2025-11-02 04:53:26 +00:00
- 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.
63 lines
1.4 KiB
TypeScript
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 };
|
|
}, {});
|
|
}
|
|
}
|