From b8cdaae8929fb001ef02d50030411d4f9b5837dd Mon Sep 17 00:00:00 2001 From: st3b1t Date: Wed, 12 Jul 2023 18:41:32 +0200 Subject: [PATCH] fix-auth-cookie --- README.md | 3 ++- lib/bitcoin/rpc.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3bdfeca..3f3c7a6 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ $ npm install satop -g $ satop --rpccookiefile=/home/user/.bitcoin/.cookie ``` -Or using username and password: +Or using username and password, if `rpccookiefile` has valid value(file exists and readble) auth method +bypass any values of `rpcuser/rpcpassword` and satop use the cookie file. ```sh $ satop --rpcuser= --rpcpassword= ``` diff --git a/lib/bitcoin/rpc.js b/lib/bitcoin/rpc.js index adde529..09eb2e5 100644 --- a/lib/bitcoin/rpc.js +++ b/lib/bitcoin/rpc.js @@ -17,7 +17,7 @@ const loadAuth = async opts => { let authType = 'usernamePassword'; - if (fs.existsSync(rpccookiefile) && (!rpcuser || !rpcpassword) ) { + if (fs.existsSync(rpccookiefile)) { authType = 'cookie'; } @@ -37,7 +37,7 @@ const loadAuth = async opts => { connect(); });*/ - if (!rpcpassword) { + if (!rpcuser || !rpcpassword) { throw new Error(`Cookie file ${rpccookiefile} in unexpected format`); } } @@ -46,8 +46,8 @@ const loadAuth = async opts => { host: rpcconnect, port: Number(rpcport), //authType, - username: rpcuser, - password: rpcpassword, + username: `${rpcuser}`.trim(), + password: `${rpcpassword}`.trim(), timeout: 1000 //TODO Number(rpctimeout), }; };