(npm, { creds, ...opts })
| 33 | } |
| 34 | |
| 35 | const 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 | |
| 71 | const login = async (npm, { creds, ...opts }) => { |
| 72 | const authType = npm.config.get('auth-type') |
nothing calls this directly
no test coverage detected
searching dependent graphs…