blob: cf82ff5b04915e5989d8a342876ec2146a2b9785 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
module.exports = adduser
const log = require('npmlog')
const npm = require('./npm.js')
const usage = require('./utils/usage')
let crypto
try {
crypto = require('crypto')
} catch (ex) {}
adduser.usage = usage(
'adduser',
'npm adduser [--registry=url] [--scope=@orgname] [--auth-type=legacy] [--always-auth]'
)
function adduser (args, cb) {
if (!crypto) {
return cb(new Error(
'You must compile node with ssl support to use the adduser feature'
))
}
let registry = npm.config.get('registry')
const scope = npm.config.get('scope')
const creds = npm.config.getCredentialsByURI(npm.config.get('registry'))
if (scope) {
const scopedRegistry = npm.config.get(scope + ':registry')
const cliRegistry = npm.config.get('registry', 'cli')
if (scopedRegistry && !cliRegistry) registry = scopedRegistry
}
log.disableProgress()
let auth
try {
auth = require('./auth/' + npm.config.get('auth-type'))
} catch (e) {
return cb(new Error('no such auth module'))
}
auth.login(creds, registry, scope, function (err, newCreds) {
if (err) return cb(err)
npm.config.del('_token', 'user') // prevent legacy pollution
if (scope) npm.config.set(scope + ':registry', registry, 'user')
npm.config.setCredentialsByURI(registry, newCreds)
npm.config.save('user', cb)
})
}
|