node/deps/npm/lib/logout.js
Rebecca Turner 41923c0c07 deps: upgrade npm to 3.3.6
PR-URL: https://github.com/nodejs/node/pull/3310
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-10-22 13:56:09 -04:00

36 lines
1016 B
JavaScript

module.exports = logout
var dezalgo = require('dezalgo')
var log = require('npmlog')
var npm = require('./npm.js')
var mapToRegistry = require('./utils/map-to-registry.js')
logout.usage = 'npm logout [--registry=<url>] [--scope=<@scope>]'
function logout (args, cb) {
cb = dezalgo(cb)
mapToRegistry('/', npm.config, function (err, uri, auth, normalized) {
if (err) return cb(err)
if (auth.token) {
log.verbose('logout', 'clearing session token for', normalized)
npm.registry.logout(normalized, { auth: auth }, function (err) {
if (err) return cb(err)
npm.config.clearCredentialsByURI(normalized)
npm.config.save('user', cb)
})
} else if (auth.username || auth.password) {
log.verbose('logout', 'clearing user credentials for', normalized)
npm.config.clearCredentialsByURI(normalized)
npm.config.save('user', cb)
} else {
cb(new Error(
'Not logged in to', normalized + ',', "so can't log out."
))
}
})
}