return db settings only to client, sanitize keys

This commit is contained in:
Alex Holliday committed 2025-05-08 13:24:24 -07:00
1 parent 91c2f7f0d5
commit 7a855ef47a
2 files changed
+13 -10

No files matched your search

+8 -10
View File
@@ -11,16 +11,15 @@ class SettingsController {
} }
getAppSettings = async (req, res, next) => { getAppSettings = async (req, res, next) => {
try { const dbSettings = await this.settingsService.getDBSettings();
const settings = { ...(await this.settingsService.getSettings()) }; const sanitizedSettings = { ...dbSettings };
delete settings.jwtSecret; if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
return res.success({ sanitizedSettings.pagespeedApiKey = "********";
msg: this.stringService.getAppSettings,
data: settings,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "getAppSettings"));
} }
return res.success({
msg: this.stringService.getAppSettings,
data: sanitizedSettings,
});
}; };
updateAppSettings = async (req, res, next) => { updateAppSettings = async (req, res, next) => {
@@ -32,7 +31,6 @@ class SettingsController {
} }
try { try {
console.log(req.body);
await this.db.updateAppSettings(req.body); await this.db.updateAppSettings(req.body);
const updatedSettings = { ...(await this.settingsService.reloadSettings()) }; const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
delete updatedSettings.jwtSecret; delete updatedSettings.jwtSecret;
+5
View File
@@ -54,6 +54,11 @@ class SettingsService {
} }
return this.settings; return this.settings;
} }
async getDBSettings() {
const settings = await this.appSettings.findOne({ singleton: true }).lean();
return settings;
}
} }
export default SettingsService; export default SettingsService;