(npm, opts, fn)
| 4 | const read = require('../utils/read-user-info.js') |
| 5 | |
| 6 | const otplease = async (npm, opts, fn) => { |
| 7 | try { |
| 8 | return await fn(opts) |
| 9 | } catch (err) { |
| 10 | if (!process.stdin.isTTY || !process.stdout.isTTY) { |
| 11 | throw err |
| 12 | } |
| 13 | |
| 14 | // web otp |
| 15 | if (err.code === 'EOTP' && err.body?.authUrl && err.body?.doneUrl) { |
| 16 | const { token: otp } = await webAuthOpener( |
| 17 | createOpener(npm, 'Authenticate your account at'), |
| 18 | err.body.authUrl, |
| 19 | err.body.doneUrl, |
| 20 | opts |
| 21 | ) |
| 22 | return await fn({ ...opts, otp }) |
| 23 | } |
| 24 | |
| 25 | // classic otp |
| 26 | if (err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body))) { |
| 27 | const otp = await read.otp('This operation requires a one-time password.\nEnter OTP:') |
| 28 | return await fn({ ...opts, otp }) |
| 29 | } |
| 30 | |
| 31 | throw err |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | const adduser = async (npm, { creds, ...opts }) => { |
| 36 | const authType = npm.config.get('auth-type') |
no test coverage detected
searching dependent graphs…