Skip to content

Commit 35cf70f

Browse files
committed
fix: prevent concurrent auth attempts from overwriting each other's challenges
1 parent 68d2f0d commit 35cf70f

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/app_auth.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface AppAuth {
1919
export class AppTokenManager {
2020
private token: string | null = null
2121
private tokenExpiresAt: number = 0
22+
private pending: Promise<string> | null = null
2223

2324
constructor(private auth: AppAuth) {}
2425

@@ -27,7 +28,14 @@ export class AppTokenManager {
2728
return this.token
2829
}
2930

30-
return await this.authenticate()
31+
if (this.pending) {
32+
return await this.pending
33+
}
34+
35+
this.pending = this.authenticate().finally(() => {
36+
this.pending = null
37+
})
38+
return await this.pending
3139
}
3240

3341
private async authenticate(): Promise<string> {

0 commit comments

Comments
 (0)