1 module.exports = logout
3 var dezalgo = require("dezalgo")
4 var log = require("npmlog")
6 var npm = require("./npm.js")
7 var mapToRegistry = require("./utils/map-to-registry.js")
9 logout.usage = "npm logout [--registry] [--scope]"
11 function logout (args, cb) {
15 mapToRegistry("/", npm.config, function (err, uri, auth, normalized) {
16 if (err) return cb(err)
19 log.verbose("logout", "clearing session token for", normalized)
20 npm.registry.logout(normalized, { auth: auth }, function (err) {
21 if (err) return cb(err)
23 npm.config.clearCredentialsByURI(normalized)
25 npm.config.save("user", cb)
28 else if (auth.username || auth.password) {
29 log.verbose("logout", "clearing user credentials for", normalized)
30 npm.config.clearCredentialsByURI(normalized)
32 npm.config.save("user", cb)
36 "Not logged in to", normalized + ",", "so can't log out."