node/deps/npm/lib/utils/otplease.js
npm team 76d85a82ea deps: upgrade npm to 8.5.5
PR-URL: https://github.com/nodejs/node/pull/42382
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-03-18 18:55:25 -07:00

18 lines
508 B
JavaScript

const readUserInfo = require('./read-user-info.js')
module.exports = otplease
async function otplease (opts, fn) {
try {
await fn(opts)
} catch (err) {
if (err.code !== 'EOTP' && (err.code !== 'E401' || !/one-time pass/.test(err.body))) {
throw err
} else if (!process.stdin.isTTY || !process.stdout.isTTY) {
throw err
} else {
const otp = await readUserInfo.otp('This operation requires a one-time password.\nEnter OTP:')
return fn({ ...opts, otp })
}
}
}