Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/app_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface AppAuth {
export class AppTokenManager {
private token: string | null = null
private tokenExpiresAt: number = 0
private pending: Promise<string> | null = null

constructor(private auth: AppAuth) {}

Expand All @@ -27,7 +28,14 @@ export class AppTokenManager {
return this.token
}

return await this.authenticate()
if (this.pending) {
return await this.pending
}

this.pending = this.authenticate().finally(() => {
this.pending = null
})
return await this.pending
}

private async authenticate(): Promise<string> {
Expand Down
Loading