1const EventEmitter = require('events') 2const { webAuthCheckLogin } = require('npm-profile') 3 4async function webAuth (opener, initialUrl, doneUrl, opts) { 5 const doneEmitter = new EventEmitter() 6 7 const openPromise = opener(initialUrl, doneEmitter) 8 const webAuthCheckPromise = webAuthCheckLogin(doneUrl, { ...opts, cache: false }) 9 .then(authResult => { 10 // cancel open prompt if it's present 11 doneEmitter.emit('abort') 12 13 return authResult.token 14 }) 15 16 await openPromise 17 return await webAuthCheckPromise 18} 19 20module.exports = webAuth 21