@@ -22,7 +22,7 @@ class BaseCommand extends Command {
22
22
async init ( err ) {
23
23
const projectRoot = findRoot ( process . cwd ( ) )
24
24
// Grab netlify API token
25
- const token = this . configToken
25
+ const token = getConfigToken ( )
26
26
27
27
// Get site config from netlify.toml
28
28
const configPath = getConfigPath ( projectRoot )
@@ -63,11 +63,6 @@ class BaseCommand extends Command {
63
63
this . netlify . api . accessToken = token
64
64
}
65
65
66
- get configToken ( ) {
67
- const userId = globalConfig . get ( 'userId' )
68
- return globalConfig . get ( `users.${ userId } .auth.token` )
69
- }
70
-
71
66
async isLoggedIn ( ) {
72
67
try {
73
68
await this . netlify . api . getCurrentUser ( )
@@ -78,7 +73,7 @@ class BaseCommand extends Command {
78
73
}
79
74
80
75
async authenticate ( authToken ) {
81
- const token = authToken || process . env . NETLIFY_AUTH_TOKEN || this . configToken
76
+ const token = getConfigToken ( authToken )
82
77
if ( ! token ) {
83
78
return this . expensivelyAuthenticate ( )
84
79
} else {
@@ -152,4 +147,18 @@ class BaseCommand extends Command {
152
147
}
153
148
}
154
149
150
+ function getConfigToken ( authTokenFromFlag ) {
151
+ // 1. First honor command flag --auth
152
+ if ( authTokenFromFlag ) {
153
+ return authTokenFromFlag
154
+ }
155
+ // 2. then Check ENV var
156
+ if ( process . env . NETLIFY_AUTH_TOKEN ) {
157
+ return process . env . NETLIFY_AUTH_TOKEN
158
+ }
159
+ // 3. If no env var use global user setting
160
+ const userId = globalConfig . get ( 'userId' )
161
+ return globalConfig . get ( `users.${ userId } .auth.token` )
162
+ }
163
+
155
164
module . exports = BaseCommand
0 commit comments