From 6f86ad26e9121fd7c5358e6286baece2ea05b155 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 19 Sep 2024 21:10:17 -0700 Subject: [PATCH] workos bug fix --- extensions/vscode/src/stubs/SecretStorage.ts | 6 ++++-- extensions/vscode/src/stubs/WorkOsAuthProvider.ts | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/src/stubs/SecretStorage.ts b/extensions/vscode/src/stubs/SecretStorage.ts index a12f313ae..4c85dfb01 100644 --- a/extensions/vscode/src/stubs/SecretStorage.ts +++ b/extensions/vscode/src/stubs/SecretStorage.ts @@ -92,13 +92,15 @@ export class SecretStorage { } async store(key: string, value: string): Promise { - const encryptedValue = await this.encrypt(value, this.keyToFilepath(key)); + const filePath = this.keyToFilepath(key); + await this.encrypt(value, filePath); } async get(key: string): Promise { const filePath = this.keyToFilepath(key); if (fs.existsSync(filePath)) { - return await this.decrypt(filePath); + const value = await this.decrypt(filePath); + return value; } return undefined; } diff --git a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts index bf5472d3d..ce3af8ff7 100644 --- a/extensions/vscode/src/stubs/WorkOsAuthProvider.ts +++ b/extensions/vscode/src/stubs/WorkOsAuthProvider.ts @@ -137,19 +137,24 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { if (!this._sessions.length) { return; } + + const finalSessions = []; for (const session of this._sessions) { try { const newSession = await this._refreshSession(session.refreshToken); session.accessToken = newSession.accessToken; session.refreshToken = newSession.refreshToken; session.expiresIn = newSession.expiresIn; + finalSessions.push(session); } catch (e: any) { if (e.message === "Network failure") { setTimeout(() => this._refreshSessions(), 60 * 1000); return; } + console.debug(`Error refreshing session token: ${e.message}`); } } + this._sessions = finalSessions; await this.storeSessions(this._sessions); this._sessionChangeEmitter.fire({ added: [], @@ -157,7 +162,7 @@ export class WorkOsAuthProvider implements AuthenticationProvider, Disposable { changed: this._sessions, }); - if (this._sessions[0].expiresIn) { + if (this._sessions[0]?.expiresIn) { setTimeout( () => this._refreshSessions(), (this._sessions[0].expiresIn * 2) / 3,