Skip to content

Commit

Permalink
remove conditional chaining operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hfaulds committed Jul 13, 2022
1 parent a0fd462 commit 9241514
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/utils/otplease.js
Expand Up @@ -6,11 +6,7 @@ async function otplease (npm, opts, fn) {
throw err
}

const isClassicOTP =
err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body))
const isWebOTP = err.code === 'EOTP' && err.body?.authUrl && err.body?.doneUrl

if (isWebOTP) {
if (isWebOTP(err)) {
const webAuth = require('./web-auth')
const openUrlPrompt = require('./open-url-prompt')

Expand All @@ -26,7 +22,7 @@ async function otplease (npm, opts, fn) {
return await fn({ ...opts, otp })
}

if (isClassicOTP) {
if (isClassicOTP(err)) {
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 })
Expand All @@ -36,4 +32,15 @@ async function otplease (npm, opts, fn) {
}
}

function isWebOTP (err) {
if (!err.code === 'EOTP' || !err.body) {
return false
}
return err.body?.authUrl && err.body?.doneUrl
}

function isClassicOTP (err) {
return err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body))
}

module.exports = otplease

0 comments on commit 9241514

Please sign in to comment.