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
+11 -8

No files matched your search

+6 -8
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") {
sanitizedSettings.pagespeedApiKey = "********";
}
return res.success({ return res.success({
msg: this.stringService.getAppSettings, msg: this.stringService.getAppSettings,
data: settings, data: sanitizedSettings,
}); });
} catch (error) {
next(handleError(error, SERVICE_NAME, "getAppSettings"));
}
}; };
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;