| 13 | ] |
| 14 | |
| 15 | async exec () { |
| 16 | const scope = this.npm.config.get('scope') |
| 17 | let registry = this.npm.config.get('registry') |
| 18 | |
| 19 | if (scope) { |
| 20 | const scopedRegistry = this.npm.config.get(`${scope}:registry`) |
| 21 | const cliRegistry = this.npm.config.get('registry', 'cli') |
| 22 | if (scopedRegistry && !cliRegistry) { |
| 23 | registry = scopedRegistry |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const creds = this.npm.config.getCredentialsByURI(registry) |
| 28 | |
| 29 | log.notice('', `Log in on ${replaceInfo(registry)}`) |
| 30 | |
| 31 | const { message, newCreds } = await auth.adduser(this.npm, { |
| 32 | ...this.npm.flatOptions, |
| 33 | creds, |
| 34 | registry, |
| 35 | }) |
| 36 | |
| 37 | this.npm.config.delete('_token', 'user') // prevent legacy pollution |
| 38 | this.npm.config.setCredentialsByURI(registry, newCreds) |
| 39 | |
| 40 | if (scope) { |
| 41 | this.npm.config.set(scope + ':registry', registry, 'user') |
| 42 | } |
| 43 | |
| 44 | await this.npm.config.save('user') |
| 45 | |
| 46 | output.standard(message) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | module.exports = AddUser |