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 12b10ba
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/utils/otplease.js
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down

0 comments on commit 12b10ba

Please sign in to comment.