"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/logout.js" (11 Apr 2017, 1122 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module.exports = logout
    2 
    3 var dezalgo = require('dezalgo')
    4 var log = require('npmlog')
    5 
    6 var npm = require('./npm.js')
    7 var mapToRegistry = require('./utils/map-to-registry.js')
    8 
    9 logout.usage = 'npm logout [--registry=<url>] [--scope=<@scope>]'
   10 
   11 function afterLogout (normalized, cb) {
   12   var scope = npm.config.get('scope')
   13 
   14   if (scope) npm.config.del(scope + ':registry')
   15 
   16   npm.config.clearCredentialsByURI(normalized)
   17   npm.config.save('user', cb)
   18 }
   19 
   20 function logout (args, cb) {
   21   cb = dezalgo(cb)
   22 
   23   mapToRegistry('/', npm.config, function (err, uri, auth, normalized) {
   24     if (err) return cb(err)
   25 
   26     if (auth.token) {
   27       log.verbose('logout', 'clearing session token for', normalized)
   28       npm.registry.logout(normalized, { auth: auth }, function (err) {
   29         if (err) return cb(err)
   30 
   31         afterLogout(normalized, cb)
   32       })
   33     } else if (auth.username || auth.password) {
   34       log.verbose('logout', 'clearing user credentials for', normalized)
   35 
   36       afterLogout(normalized, cb)
   37     } else {
   38       cb(new Error(
   39         'Not logged in to', normalized + ',', "so can't log out."
   40       ))
   41     }
   42   })
   43 }