1
1
'use strict'
2
+
2
3
const read = require ( '../utils/read-user-info.js' )
3
4
const profile = require ( 'npm-profile' )
4
5
const log = require ( 'npmlog' )
5
- const npm = require ( '../npm.js' )
6
+ const figgyPudding = require ( 'figgy-pudding' )
7
+ const npmConfig = require ( '../config/figgy-config.js' )
6
8
const output = require ( '../utils/output.js' )
7
- const pacoteOpts = require ( '../config/pacote' )
8
- const fetchOpts = require ( '../config/fetch-opts' )
9
9
const openUrl = require ( '../utils/open-url' )
10
10
11
11
const openerPromise = ( url ) => new Promise ( ( resolve , reject ) => {
@@ -26,54 +26,54 @@ const loginPrompter = (creds) => {
26
26
} )
27
27
}
28
28
29
- module . exports . login = ( creds , registry , scope , cb ) => {
30
- const conf = {
31
- log : log ,
32
- creds : creds ,
33
- registry : registry ,
34
- auth : {
35
- otp : npm . config . get ( 'otp' )
36
- } ,
37
- scope : scope ,
38
- opts : fetchOpts . fromPacote ( pacoteOpts ( ) )
39
- }
40
- login ( conf ) . then ( ( newCreds ) => cb ( null , newCreds ) ) . catch ( cb )
29
+ const LoginOpts = figgyPudding ( {
30
+ 'always-auth' : { } ,
31
+ creds : { } ,
32
+ log : { default : ( ) => log } ,
33
+ registry : { } ,
34
+ scope : { }
35
+ } )
36
+
37
+ module . exports . login = ( creds = { } , registry , scope , cb ) => {
38
+ const opts = LoginOpts ( npmConfig ( ) ) . concat ( { scope, registry, creds} )
39
+ login ( opts ) . then ( ( newCreds ) => cb ( null , newCreds ) ) . catch ( cb )
41
40
}
42
41
43
- function login ( conf ) {
44
- return profile . login ( openerPromise , loginPrompter , conf )
42
+ function login ( opts ) {
43
+ return profile . login ( openerPromise , loginPrompter , opts )
45
44
. catch ( ( err ) => {
46
45
if ( err . code === 'EOTP' ) throw err
47
- const u = conf . creds . username
48
- const p = conf . creds . password
49
- const e = conf . creds . email
46
+ const u = opts . creds . username
47
+ const p = opts . creds . password
48
+ const e = opts . creds . email
50
49
if ( ! ( u && p && e ) ) throw err
51
- return profile . adduserCouch ( u , e , p , conf )
50
+ return profile . adduserCouch ( u , e , p , opts )
52
51
} )
53
52
. catch ( ( err ) => {
54
53
if ( err . code !== 'EOTP' ) throw err
55
- return read . otp ( 'Enter one-time password from your authenticator app: ' ) . then ( ( otp ) => {
56
- conf . auth . otp = otp
57
- const u = conf . creds . username
58
- const p = conf . creds . password
59
- return profile . loginCouch ( u , p , conf )
54
+ return read . otp (
55
+ 'Enter one-time password from your authenticator app: '
56
+ ) . then ( otp => {
57
+ const u = opts . creds . username
58
+ const p = opts . creds . password
59
+ return profile . loginCouch ( u , p , opts . concat ( { otp} ) )
60
60
} )
61
61
} ) . then ( ( result ) => {
62
62
const newCreds = { }
63
63
if ( result && result . token ) {
64
64
newCreds . token = result . token
65
65
} else {
66
- newCreds . username = conf . creds . username
67
- newCreds . password = conf . creds . password
68
- newCreds . email = conf . creds . email
69
- newCreds . alwaysAuth = npm . config . get ( 'always-auth' )
66
+ newCreds . username = opts . creds . username
67
+ newCreds . password = opts . creds . password
68
+ newCreds . email = opts . creds . email
69
+ newCreds . alwaysAuth = opts [ 'always-auth' ]
70
70
}
71
71
72
- const usermsg = conf . creds . username ? ' user ' + conf . creds . username : ''
73
- conf . log . info ( 'login' , 'Authorized' + usermsg )
74
- const scopeMessage = conf . scope ? ' to scope ' + conf . scope : ''
75
- const userout = conf . creds . username ? ' as ' + conf . creds . username : ''
76
- output ( 'Logged in%s%s on %s.' , userout , scopeMessage , conf . registry )
72
+ const usermsg = opts . creds . username ? ' user ' + opts . creds . username : ''
73
+ opts . log . info ( 'login' , 'Authorized' + usermsg )
74
+ const scopeMessage = opts . scope ? ' to scope ' + opts . scope : ''
75
+ const userout = opts . creds . username ? ' as ' + opts . creds . username : ''
76
+ output ( 'Logged in%s%s on %s.' , userout , scopeMessage , opts . registry )
77
77
return newCreds
78
78
} )
79
79
}
0 commit comments