mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 05:43:02 +00:00

PR-URL: https://github.com/nodejs/node/pull/35474 Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
23 lines
634 B
JavaScript
23 lines
634 B
JavaScript
'use strict'
|
|
|
|
const prompt = 'This operation requires a one-time password.\nEnter OTP:'
|
|
const readUserInfo = require('./read-user-info.js')
|
|
|
|
const isOtpError = err =>
|
|
err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body))
|
|
|
|
module.exports = otplease
|
|
function otplease (opts, fn) {
|
|
opts = { prompt, ...opts }
|
|
return Promise.resolve().then(() => fn(opts)).catch(err => {
|
|
if (!isOtpError(err)) {
|
|
throw err
|
|
} else if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
throw err
|
|
} else {
|
|
return readUserInfo.otp(opts.prompt)
|
|
.then(otp => fn({ ...opts, otp }))
|
|
}
|
|
})
|
|
}
|