workos bug fix

This commit is contained in:
Nate 2024-09-19 21:10:17 -07:00
parent 1c51b19dea
commit 6f86ad26e9
2 changed files with 10 additions and 3 deletions

View file

@ -92,13 +92,15 @@ export class SecretStorage {
}
async store(key: string, value: string): Promise<void> {
const encryptedValue = await this.encrypt(value, this.keyToFilepath(key));
const filePath = this.keyToFilepath(key);
await this.encrypt(value, filePath);
}
async get(key: string): Promise<string | undefined> {
const filePath = this.keyToFilepath(key);
if (fs.existsSync(filePath)) {
return await this.decrypt(filePath);
const value = await this.decrypt(filePath);
return value;
}
return undefined;
}

View file

@ -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,