diff --git a/backend/controllers/shared/RTLConf.js b/backend/controllers/shared/RTLConf.js index c474839b..e15233bc 100644 --- a/backend/controllers/shared/RTLConf.js +++ b/backend/controllers/shared/RTLConf.js @@ -201,17 +201,19 @@ export const updateNodeSettings = (req, res, next) => { const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index)); if (node && node.settings) { node.settings = { ...node.settings, ...req.body.settings }; - if (req.body.authentication.boltzMacaroonPath) { - node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; - } - else { - delete node.authentication.boltzMacaroonPath; - } - if (req.body.authentication.swapMacaroonPath) { - node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; - } - else { - delete node.authentication.swapMacaroonPath; + if (node.authentication && req.body.authentication) { + if (req.body.authentication.boltzMacaroonPath) { + node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; + } + else { + delete node.authentication.boltzMacaroonPath; + } + if (req.body.authentication.swapMacaroonPath) { + node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; + } + else { + delete node.authentication.swapMacaroonPath; + } } } try { @@ -219,17 +221,19 @@ export const updateNodeSettings = (req, res, next) => { const selectedNode = common.findNode(req.session.selectedNode.index); if (selectedNode && selectedNode.settings) { selectedNode.settings = { ...selectedNode.settings, ...req.body.settings }; - if (req.body.authentication.boltzMacaroonPath) { - selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; - } - else { - delete selectedNode.authentication.boltzMacaroonPath; - } - if (req.body.authentication.swapMacaroonPath) { - selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; - } - else { - delete selectedNode.authentication.swapMacaroonPath; + if (selectedNode.authentication && req.body.authentication) { + if (req.body.authentication.boltzMacaroonPath) { + selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; + } + else { + delete selectedNode.authentication.boltzMacaroonPath; + } + if (req.body.authentication.swapMacaroonPath) { + selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; + } + else { + delete selectedNode.authentication.swapMacaroonPath; + } } common.replaceNode(req, selectedNode); } diff --git a/backend/utils/common.js b/backend/utils/common.js index fea377ac..ff263243 100644 --- a/backend/utils/common.js +++ b/backend/utils/common.js @@ -55,7 +55,7 @@ export class CommonService { delete config.multiPass; delete config.multiPassHashed; delete config.secret2FA; - config.nodes?.map((node) => this.removeAuthSecureData(node)); + config.nodes?.forEach((node) => this.removeAuthSecureData(node)); return config; }; this.addSecureData = (config) => { @@ -70,7 +70,7 @@ export class CommonService { config.secret2FA = this.appConfig.secret2FA; } const appConfigNodes = new Map(this.appConfig.nodes?.map((node) => [node.index, node])); - config.nodes.map((node) => { + config.nodes.forEach((node) => { const appConfigNode = appConfigNodes.get(node.index); if (appConfigNode?.authentication) { if (appConfigNode.authentication.macaroonPath) { @@ -83,7 +83,6 @@ export class CommonService { node.authentication.lnApiPassword = appConfigNode.authentication.lnApiPassword; } } - return node; }); return config; }; diff --git a/server/controllers/shared/RTLConf.ts b/server/controllers/shared/RTLConf.ts index 724d7a45..447ce6fc 100644 --- a/server/controllers/shared/RTLConf.ts +++ b/server/controllers/shared/RTLConf.ts @@ -205,15 +205,17 @@ export const updateNodeSettings = (req, res, next) => { const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index)); if (node && node.settings) { node.settings = { ...node.settings, ...req.body.settings }; - if (req.body.authentication.boltzMacaroonPath) { - node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; - } else { - delete node.authentication.boltzMacaroonPath; - } - if (req.body.authentication.swapMacaroonPath) { - node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; - } else { - delete node.authentication.swapMacaroonPath; + if (node.authentication && req.body.authentication) { + if (req.body.authentication.boltzMacaroonPath) { + node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; + } else { + delete node.authentication.boltzMacaroonPath; + } + if (req.body.authentication.swapMacaroonPath) { + node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; + } else { + delete node.authentication.swapMacaroonPath; + } } } try { @@ -221,15 +223,17 @@ export const updateNodeSettings = (req, res, next) => { const selectedNode = common.findNode(req.session.selectedNode.index); if (selectedNode && selectedNode.settings) { selectedNode.settings = { ...selectedNode.settings, ...req.body.settings }; - if (req.body.authentication.boltzMacaroonPath) { - selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; - } else { - delete selectedNode.authentication.boltzMacaroonPath; - } - if (req.body.authentication.swapMacaroonPath) { - selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; - } else { - delete selectedNode.authentication.swapMacaroonPath; + if (selectedNode.authentication && req.body.authentication) { + if (req.body.authentication.boltzMacaroonPath) { + selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath; + } else { + delete selectedNode.authentication.boltzMacaroonPath; + } + if (req.body.authentication.swapMacaroonPath) { + selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath; + } else { + delete selectedNode.authentication.swapMacaroonPath; + } } common.replaceNode(req, selectedNode); } diff --git a/server/utils/common.ts b/server/utils/common.ts index d3418bf5..714ea1ce 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -63,7 +63,7 @@ export class CommonService { delete config.multiPass; delete config.multiPassHashed; delete config.secret2FA; - config.nodes?.map((node) => this.removeAuthSecureData(node)); + config.nodes?.forEach((node) => this.removeAuthSecureData(node)); return config; }; @@ -79,7 +79,7 @@ export class CommonService { config.secret2FA = this.appConfig.secret2FA; } const appConfigNodes = new Map(this.appConfig.nodes?.map((node) => [node.index, node])); - config.nodes.map((node) => { + config.nodes.forEach((node) => { const appConfigNode = appConfigNodes.get(node.index); if (appConfigNode?.authentication) { if (appConfigNode.authentication.macaroonPath) { @@ -92,7 +92,6 @@ export class CommonService { node.authentication.lnApiPassword = appConfigNode.authentication.lnApiPassword; } } - return node; }); return config; };