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

Function adduser

deps/npm/lib/utils/auth.js:35–69  ·  view source on GitHub ↗
(npm, { creds, ...opts })

Source from the content-addressed store, hash-verified

33}
34
35const adduser = async (npm, { creds, ...opts }) => {
36 const authType = npm.config.get('auth-type')
37 let res
38 if (authType === 'web') {
39 try {
40 res = await adduserWeb(createOpener(npm, 'Create your account at'), opts)
41 } catch (err) {
42 if (err.code === 'ENYI') {
43 log.verbose('web add user not supported, trying couch')
44 } else {
45 throw err
46 }
47 }
48 }
49
50 // auth type !== web or ENYI error w/ web adduser
51 if (!res) {
52 const username = await read.username('Username:', creds.username)
53 const password = await read.password('Password:', creds.password)
54 const email = await read.email('Email (this will be public):', creds.email)
55 // npm registry quirk:
56 // If you "add" an existing user with their current password, it's effectively a login, and if that account has otp you'll be prompted for it.
57 res = await otplease(npm, opts, (reqOpts) => adduserCouch(username, email, password, reqOpts))
58 }
59
60 // We don't know the username if it was a web login, all we can reliably log is scope and registry
61 const message = `Logged in${opts.scope ? ` to scope ${opts.scope}` : ''} on ${opts.registry}.`
62
63 log.info('adduser', message)
64
65 return {
66 message,
67 newCreds: { token: res.token },
68 }
69}
70
71const login = async (npm, { creds, ...opts }) => {
72 const authType = npm.config.get('auth-type')

Callers

nothing calls this directly

Calls 7

createOpenerFunction · 0.85
otpleaseFunction · 0.85
verboseMethod · 0.80
usernameMethod · 0.80
passwordMethod · 0.80
infoMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…