diff --git a/lib/utils/otplease.js b/lib/utils/otplease.js index 83985b6bc170d..b3f355ea340df 100644 --- a/lib/utils/otplease.js +++ b/lib/utils/otplease.js @@ -1,16 +1,23 @@ +const jsonParse = require('json-parse-even-better-errors') + 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) { + if (!process.stdin.isTTY || !process.stdout.isTTY) { throw err - } else { + } + + const isBackwardsCompatibleOTP = err.code === 'E401' && /one-time pass/.test(err.body) + const isClassicOTP = err.code === 'EOTP' && /one-time pass/.test(err.body?.error) + + if (isClassicOTP || isBackwardsCompatibleOTP) { + const readUserInfo = require('./read-user-info.js') const otp = await readUserInfo.otp('This operation requires a one-time password.\nEnter OTP:') return await fn({ ...opts, otp }) } + + throw err } }