MCPcopy Index your code
hub / github.com/nodejs/node / otplease

Function otplease

deps/npm/lib/utils/auth.js:6–33  ·  view source on GitHub ↗
(npm, opts, fn)

Source from the content-addressed store, hash-verified

4const read = require('../utils/read-user-info.js')
5
6const 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
35const adduser = async (npm, { creds, ...opts }) => {
36 const authType = npm.config.get('auth-type')

Callers 15

createConfigMethod · 0.85
adduserFunction · 0.85
loginFunction · 0.85
setMethod · 0.85
enable2faMethod · 0.85
disable2faMethod · 0.85
#grantMethod · 0.85
#revokeMethod · 0.85
#setMfaMethod · 0.85
#setStatusMethod · 0.85
#publishMethod · 0.85
execMethod · 0.85

Calls 3

createOpenerFunction · 0.85
fnFunction · 0.50
testMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…