Skip to content
This repository was archived by the owner on Aug 10, 2020. It is now read-only.

Commit 5b080b3

Browse files
committed
Remove getter and lookup by flag > env var > global user config
1 parent 6af91ae commit 5b080b3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BaseCommand extends Command {
2222
async init(err) {
2323
const projectRoot = findRoot(process.cwd())
2424
// Grab netlify API token
25-
const token = this.configToken
25+
const token = getConfigToken()
2626

2727
// Get site config from netlify.toml
2828
const configPath = getConfigPath(projectRoot)
@@ -63,11 +63,6 @@ class BaseCommand extends Command {
6363
this.netlify.api.accessToken = token
6464
}
6565

66-
get configToken() {
67-
const userId = globalConfig.get('userId')
68-
return globalConfig.get(`users.${userId}.auth.token`)
69-
}
70-
7166
async isLoggedIn() {
7267
try {
7368
await this.netlify.api.getCurrentUser()
@@ -78,7 +73,7 @@ class BaseCommand extends Command {
7873
}
7974

8075
async authenticate(authToken) {
81-
const token = authToken || process.env.NETLIFY_AUTH_TOKEN || this.configToken
76+
const token = getConfigToken(authToken)
8277
if (!token) {
8378
return this.expensivelyAuthenticate()
8479
} else {
@@ -152,4 +147,18 @@ class BaseCommand extends Command {
152147
}
153148
}
154149

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+
155164
module.exports = BaseCommand

0 commit comments

Comments
 (0)