From cf6be7ca15c664c0a82c9826e4ee4bec26f9c2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller=20Ellehauge?= Date: Mon, 27 Jun 2022 11:08:06 +0200 Subject: [PATCH] refactor: change flow of otplease --- lib/utils/otplease.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/utils/otplease.js b/lib/utils/otplease.js index 83985b6bc170d..bfae8152c8e07 100644 --- a/lib/utils/otplease.js +++ b/lib/utils/otplease.js @@ -2,15 +2,21 @@ 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) { + } + + if (err.code !== 'EOTP' && err.code !== 'E401') { throw err - } else { + } + + if (/one-time pass/.test(err.body)) { + 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 } }