Skip to content

Commit

Permalink
refactor: change flow of otplease
Browse files Browse the repository at this point in the history
  • Loading branch information
jumoel committed Jun 29, 2022
1 parent 0ce09f1 commit d0af95f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/utils/otplease.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ 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))) {
if (!process.stdin.isTTY || !process.stdout.isTTY) {
throw err
} else 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'

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
}
}

Expand Down

0 comments on commit d0af95f

Please sign in to comment.