]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/whoami.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / whoami.js
1 var npm = require("./npm.js")
2
3 module.exports = whoami
4
5 whoami.usage = "npm whoami\n(just prints username according to given registry)"
6
7 function whoami (args, silent, cb) {
8   // FIXME: need tighter checking on this, but is a breaking change
9   if (typeof cb !== "function") {
10     cb = silent
11     silent = false
12   }
13
14   var registry = npm.config.get("registry")
15   if (!registry) return cb(new Error("no default registry set"))
16
17   var auth = npm.config.getCredentialsByURI(registry)
18   if (auth) {
19     if (auth.username) {
20       if (!silent) console.log(auth.username)
21       return process.nextTick(cb.bind(this, null, auth.username))
22     }
23     else if (auth.token) {
24       return npm.registry.whoami(registry, { auth : auth }, function (er, username) {
25         if (er) return cb(er)
26         if (!username) {
27           var needNewSession = new Error(
28             "Your auth token is no longer valid. Please log in again."
29           )
30           needNewSession.code = 'ENEEDAUTH'
31           return cb(needNewSession)
32         }
33
34         if (!silent) console.log(username)
35         cb(null, username)
36       })
37     }
38   }
39
40   // At this point, if they have a credentials object, it doesn't have a token
41   // or auth in it.  Probably just the default registry.
42   var needAuth = new Error(
43     "this command requires you to be logged in."
44   )
45   needAuth.code = 'ENEEDAUTH'
46   process.nextTick(cb.bind(this, needAuth))
47 }