diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-03-04 05:27:07 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-03-04 05:27:07 +0300 |
commit | 1b8ba7426393cbae2c76ad2c35953782d4401871 (patch) | |
tree | 86e0fb619d377741d25b24d4fefc80f92398aa26 /lib/whoami.js | |
parent | 7691d8229b45f79e06ea65bd4618d57ca9abea7b (diff) |
`npm stars` don't send bogus auth when not authed
Fixes #7531.
Diffstat (limited to 'lib/whoami.js')
-rw-r--r-- | lib/whoami.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/whoami.js b/lib/whoami.js index 42cede1b8..d92a6574a 100644 --- a/lib/whoami.js +++ b/lib/whoami.js @@ -14,14 +14,6 @@ function whoami (args, silent, cb) { var registry = npm.config.get("registry") if (!registry) return cb(new Error("no default registry set")) - function noUser () { - // 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) - cb(null, msg) - } - var auth = npm.config.getCredentialsByURI(registry) if (auth) { if (auth.username) { @@ -31,7 +23,13 @@ function whoami (args, silent, cb) { else if (auth.token) { return npm.registry.whoami(registry, { auth : auth }, function (er, username) { if (er) return cb(er) - if (!username) return noUser() + if (!username) { + var needNewSession = new Error( + "Your auth token is no longer valid. Please log in again." + ) + needNewSession.code = 'ENEEDAUTH' + return cb(needNewSession) + } if (!silent) console.log(username) cb(null, username) @@ -39,5 +37,11 @@ function whoami (args, silent, cb) { } } - process.nextTick(noUser) + // 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 needAuth = new Error( + "'npm whoami' requires you to be logged in." + ) + needAuth.code = 'ENEEDAUTH' + process.nextTick(cb.bind(this, needAuth)) } |