Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-03-10 18:41:46 +0300
committerGitHub <noreply@github.com>2022-03-10 18:41:46 +0300
commit5c06a33e641594c5617a0606c338fc54c64d623b (patch)
tree4060f2fe3c4adbcec07d13b31eea83340e14f788 /lib/utils
parent55ab38c5337de76b739c4f0cdfb8932dc5420ce4 (diff)
fix: clean up owner command and otplease (#4528)
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/otplease.js19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/utils/otplease.js b/lib/utils/otplease.js
index 0e32493f9..566c24ef2 100644
--- a/lib/utils/otplease.js
+++ b/lib/utils/otplease.js
@@ -1,20 +1,17 @@
-const prompt = 'This operation requires a one-time password.\nEnter OTP:'
const readUserInfo = require('./read-user-info.js')
-const isOtpError = err =>
- err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body))
-
module.exports = otplease
-function otplease (opts, fn) {
- opts = { prompt, ...opts }
- return Promise.resolve().then(() => fn(opts)).catch(err => {
- if (!isOtpError(err)) {
+async function otplease (opts, fn) {
+ try {
+ await fn(opts)
+ } catch (err) {
+ if (err.code !== 'EOTP' && (err.code !== 'E401' || !/one-time pass/.test(err.body))) {
throw err
} else if (!process.stdin.isTTY || !process.stdout.isTTY) {
throw err
} else {
- return readUserInfo.otp(opts.prompt)
- .then(otp => fn({ ...opts, otp }))
+ const otp = await readUserInfo.otp('This operation requires a one-time password.\nEnter OTP:')
+ return fn({ ...opts, otp })
}
- })
+ }
}