mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 08:52:55 +00:00

PR-URL: https://github.com/nodejs/node/pull/42550 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
18 lines
525 B
JavaScript
18 lines
525 B
JavaScript
async function otplease (opts, fn) {
|
|
try {
|
|
return await fn(opts)
|
|
} catch (err) {
|
|
const readUserInfo = require('./read-user-info.js')
|
|
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 await fn({ ...opts, otp })
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = otplease
|