Updated secrets held in env vars.

This commit is contained in:
Tom Butcher 2025-12-13 23:54:29 +00:00
parent d9247d2504
commit b443c28e4b
3 changed files with 27 additions and 18 deletions

View File

@ -1,9 +1,2 @@
DB_LINK="mongo-link-to-connect" SESSION_SECRET='SECRET'
KEYCLOAK_CLIENT_SECRET='SECRET'
JWT_SECRET="token"
APP_URL_CLIENT=https://material-dashboard-react-node.creative-tim.com
APP_URL_API=https://node-json-api-free.creative-tim.com/login
MAILTRAP_USER=
MAILTRAP_PASSWORD=

View File

@ -9,11 +9,9 @@
"keycloak": { "keycloak": {
"url": "https://auth.tombutcher.work", "url": "https://auth.tombutcher.work",
"realm": "master", "realm": "master",
"clientId": "farmcontrol-client", "clientId": "farmcontrol-client"
"clientSecret": "REDACTED"
}, },
"requiredRoles": [], "requiredRoles": []
"sessionSecret": "REDACTED"
}, },
"app": { "app": {
"urlClient": "http://localhost:3000", "urlClient": "http://localhost:3000",
@ -60,11 +58,9 @@
"keycloak": { "keycloak": {
"url": "https://auth.tombutcher.work", "url": "https://auth.tombutcher.work",
"realm": "master", "realm": "master",
"clientId": "farmcontrol-client", "clientId": "farmcontrol-client"
"clientSecret": "REDACTED"
}, },
"requiredRoles": [], "requiredRoles": []
"sessionSecret": "REDACTED"
}, },
"app": { "app": {
"urlClient": "http://localhost:3000", "urlClient": "http://localhost:3000",

View File

@ -25,7 +25,27 @@ function loadConfig() {
throw new Error(`Configuration for environment '${NODE_ENV}' not found in config.json`); throw new Error(`Configuration for environment '${NODE_ENV}' not found in config.json`);
} }
return config[NODE_ENV]; const envConfig = config[NODE_ENV];
// Override secrets with environment variables if available
if (process.env.KEYCLOAK_CLIENT_SECRET) {
if (!envConfig.auth) {
envConfig.auth = {};
}
if (!envConfig.auth.keycloak) {
envConfig.auth.keycloak = {};
}
envConfig.auth.keycloak.clientSecret = process.env.KEYCLOAK_CLIENT_SECRET;
}
if (process.env.SESSION_SECRET) {
if (!envConfig.auth) {
envConfig.auth = {};
}
envConfig.auth.sessionSecret = process.env.SESSION_SECRET;
}
return envConfig;
} catch (err) { } catch (err) {
console.error('Error loading config:', err); console.error('Error loading config:', err);
throw err; throw err;