From 8423d4f133a40c8ceb0e1a75d23aa95fbf4f5b65 Mon Sep 17 00:00:00 2001 From: Gar Date: Fri, 6 Oct 2023 10:06:21 -0700 Subject: [PATCH] fix: delete auth from proper location on logout --- lib/commands/logout.js | 9 ++++++--- workspaces/config/lib/index.js | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/commands/logout.js b/lib/commands/logout.js index aea5e93652b0e..ef0f256568d2c 100644 --- a/lib/commands/logout.js +++ b/lib/commands/logout.js @@ -19,6 +19,9 @@ class Logout extends BaseCommand { const auth = getAuth(reg, this.npm.flatOptions) + const level = this.npm.config.find(`${auth.regKey}:${auth.authKey}`) + + // find the config level and only delete from there if (auth.token) { log.verbose('logout', `clearing token for ${reg}`) await npmFetch(`/-/user/token/${encodeURIComponent(auth.token)}`, { @@ -34,12 +37,12 @@ class Logout extends BaseCommand { } if (scope) { - this.npm.config.delete(regRef, 'user') + this.npm.config.delete(regRef, level) } - this.npm.config.clearCredentialsByURI(reg) + this.npm.config.clearCredentialsByURI(reg, level) - await this.npm.config.save('user') + await this.npm.config.save(level) } } module.exports = Logout diff --git a/workspaces/config/lib/index.js b/workspaces/config/lib/index.js index ad07fcdf51826..b09ecc478f64f 100644 --- a/workspaces/config/lib/index.js +++ b/workspaces/config/lib/index.js @@ -774,29 +774,29 @@ class Config { await chmod(conf.source, mode) } - clearCredentialsByURI (uri) { + clearCredentialsByURI (uri, level = 'user') { const nerfed = nerfDart(uri) const def = nerfDart(this.get('registry')) if (def === nerfed) { - this.delete(`-authtoken`, 'user') - this.delete(`_authToken`, 'user') - this.delete(`_authtoken`, 'user') - this.delete(`_auth`, 'user') - this.delete(`_password`, 'user') - this.delete(`username`, 'user') + this.delete(`-authtoken`, level) + this.delete(`_authToken`, level) + this.delete(`_authtoken`, level) + this.delete(`_auth`, level) + this.delete(`_password`, level) + this.delete(`username`, level) // de-nerf email if it's nerfed to the default registry - const email = this.get(`${nerfed}:email`, 'user') + const email = this.get(`${nerfed}:email`, level) if (email) { - this.set('email', email, 'user') + this.set('email', email, level) } } - this.delete(`${nerfed}:_authToken`, 'user') - this.delete(`${nerfed}:_auth`, 'user') - this.delete(`${nerfed}:_password`, 'user') - this.delete(`${nerfed}:username`, 'user') - this.delete(`${nerfed}:email`, 'user') - this.delete(`${nerfed}:certfile`, 'user') - this.delete(`${nerfed}:keyfile`, 'user') + this.delete(`${nerfed}:_authToken`, level) + this.delete(`${nerfed}:_auth`, level) + this.delete(`${nerfed}:_password`, level) + this.delete(`${nerfed}:username`, level) + this.delete(`${nerfed}:email`, level) + this.delete(`${nerfed}:certfile`, level) + this.delete(`${nerfed}:keyfile`, level) } setCredentialsByURI (uri, { token, username, password, email, certfile, keyfile }) {