Skip to content

Commit 145f81e

Browse files
committed
fix: memoize auth token
1 parent 367c4ac commit 145f81e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/api_client.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class APIClient {
4141
preauthPromises: { [k: string]: Promise<HTTP> }
4242
http: typeof HTTP
4343
private _twoFactorMutex: Mutex<string> | undefined
44+
private _auth?: string
4445

4546
constructor(protected config: Config.IConfig, public options: IOptions = {}) {
4647
this.config = config
@@ -110,13 +111,16 @@ export class APIClient {
110111
}
111112

112113
get auth(): string | undefined {
113-
if (process.env.HEROKU_API_TOKEN) deps.cli.warn('HEROKU_API_TOKEN is set but you probably meant HEROKU_API_KEY')
114-
let auth = process.env.HEROKU_API_KEY
115-
if (!auth) {
116-
deps.netrc.loadSync()
117-
auth = deps.netrc.machines[vars.apiHost] && deps.netrc.machines[vars.apiHost].password
114+
if (!this._auth) {
115+
this._auth = process.env.HEROKU_API_KEY
116+
if (this._auth) {
117+
deps.cli.warn('HEROKU_API_TOKEN is set but you probably meant HEROKU_API_KEY')
118+
} else {
119+
deps.netrc.loadSync()
120+
this._auth = deps.netrc.machines[vars.apiHost] && deps.netrc.machines[vars.apiHost].password
121+
}
118122
}
119-
return auth
123+
return this._auth
120124
}
121125

122126
twoFactorPrompt() {

0 commit comments

Comments
 (0)