|
2 | 2 |
|
3 | 3 | const fetch = require('npm-registry-fetch')
|
4 | 4 | const { HttpErrorBase } = require('npm-registry-fetch/lib/errors')
|
| 5 | +const EventEmitter = require('events') |
5 | 6 | const os = require('os')
|
6 | 7 | const { URL } = require('url')
|
7 | 8 | const log = require('proc-log')
|
@@ -73,8 +74,23 @@ const webAuth = (opener, opts, body) => {
|
73 | 74 | return content
|
74 | 75 | }).then(({ doneUrl, loginUrl }) => {
|
75 | 76 | log.verbose('web auth', 'opening url pair')
|
76 |
| - return opener(loginUrl).then( |
77 |
| - () => webAuthCheckLogin(doneUrl, { ...opts, cache: false }) |
| 77 | + |
| 78 | + const doneEmitter = new EventEmitter() |
| 79 | + |
| 80 | + const openPromise = opener(loginUrl, doneEmitter) |
| 81 | + const webAuthCheckPromise = webAuthCheckLogin(doneUrl, { ...opts, cache: false }) |
| 82 | + .then(authResult => { |
| 83 | + log.verbose('web auth', 'done-check finished') |
| 84 | + |
| 85 | + // cancel open prompt if it's present |
| 86 | + doneEmitter.emit('abort') |
| 87 | + |
| 88 | + return authResult |
| 89 | + }) |
| 90 | + |
| 91 | + return Promise.all([openPromise, webAuthCheckPromise]).then( |
| 92 | + // pick the auth result and pass it along |
| 93 | + ([, authResult]) => authResult |
78 | 94 | )
|
79 | 95 | }).catch(er => {
|
80 | 96 | if ((er.statusCode >= 400 && er.statusCode <= 499) || er.statusCode === 500) {
|
|
0 commit comments