amis-rpc-design/node_modules/npm/lib/utils/web-auth.js

21 lines
558 B
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
const EventEmitter = require('events')
const { webAuthCheckLogin } = require('npm-profile')
async function webAuth (opener, initialUrl, doneUrl, opts) {
const doneEmitter = new EventEmitter()
const openPromise = opener(initialUrl, doneEmitter)
const webAuthCheckPromise = webAuthCheckLogin(doneUrl, { ...opts, cache: false })
.then(authResult => {
// cancel open prompt if it's present
doneEmitter.emit('abort')
return authResult.token
})
await openPromise
return await webAuthCheckPromise
}
module.exports = webAuth