MCPcopy Create free account
hub / github.com/npm/cli / exec

Method exec

lib/commands/logout.js:14–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12 ]
13
14 async exec () {
15 const registry = this.npm.config.get('registry')
16 const scope = this.npm.config.get('scope')
17 const regRef = scope ? `${scope}:registry` : 'registry'
18 const reg = this.npm.config.get(regRef) || registry
19
20 const auth = getAuth(reg, this.npm.flatOptions)
21
22 const level = this.npm.config.find(`${auth.regKey}:${auth.authKey}`)
23
24 // find the config level and only delete from there
25 if (auth.token) {
26 log.verbose('logout', `clearing token for ${reg}`)
27 await npmFetch(`/-/user/token/${encodeURIComponent(auth.token)}`, {
28 ...this.npm.flatOptions,
29 registry: reg,
30 method: 'DELETE',
31 ignoreBody: true,
32 })
33 } else if (auth.isBasicAuth) {
34 log.verbose('logout', `clearing user credentials for ${reg}`)
35 } else {
36 const msg = `not logged in to ${reg}, so can't log out!`
37 throw Object.assign(new Error(msg), { code: 'ENEEDAUTH' })
38 }
39
40 if (scope) {
41 this.npm.config.delete(regRef, level)
42 }
43
44 this.npm.config.clearCredentialsByURI(reg, level)
45
46 await this.npm.config.save(level)
47 }
48}
49
50module.exports = Logout

Callers

nothing calls this directly

Calls 6

npmFetchFunction · 0.85
findMethod · 0.80
clearCredentialsByURIMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected