Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-07-12 01:23:58 +0400
committerisaacs <i@izs.me>2014-07-12 01:23:58 +0400
commite410861c69a3799c1874614cb5b87af8124ff98d (patch)
tree46afe6470fadf1b9e82ffb7d60515a1ded4cd68f /lib/whoami.js
parent10bc776649167bfd1147efac1a03918e600d0f1a (diff)
whoami: Don't crash if we don't have a username
The 'credentials' var will always be truthy, because there's always *some* registry URI. See also npm/npmconf#40
Diffstat (limited to 'lib/whoami.js')
-rw-r--r--lib/whoami.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/whoami.js b/lib/whoami.js
index 654c539e6..b33f93743 100644
--- a/lib/whoami.js
+++ b/lib/whoami.js
@@ -18,23 +18,22 @@ function whoami (args, silent, cb) {
if (credentials) {
if (credentials.username) {
if (!silent) console.log(credentials.username)
- process.nextTick(cb.bind(this, null, credentials.username))
+ return process.nextTick(cb.bind(this, null, credentials.username))
}
else if (credentials.token) {
- npm.registry.whoami(registry, function (er, username) {
+ return npm.registry.whoami(registry, function (er, username) {
if (er) return cb(er)
if (!silent) console.log(username)
cb(null, username)
})
}
- else {
- process.nextTick(cb.bind(this, new Error("credentials without username or token")))
- }
- }
- else {
- var msg = "Not authed. Run 'npm adduser'"
- if (!silent) console.log(msg)
- process.nextTick(cb.bind(this, null, msg))
}
+
+ // At this point, if they have a credentials object, it doesn't
+ // have a token or auth in it. Probably just the default
+ // registry.
+ var msg = "Not authed. Run 'npm adduser'"
+ if (!silent) console.log(msg)
+ process.nextTick(cb.bind(this, null, msg))
}