diff --git a/packages/cloud/src/SettingsService.ts b/packages/cloud/src/SettingsService.ts index 3ee56000e8..e46b488d42 100644 --- a/packages/cloud/src/SettingsService.ts +++ b/packages/cloud/src/SettingsService.ts @@ -25,8 +25,7 @@ export class SettingsService { this.timer = new RefreshTimer({ callback: async () => { - await this.fetchSettings(callback) - return true + return await this.fetchSettings(callback) }, successInterval: 30000, initialBackoffMs: 1000, @@ -42,10 +41,6 @@ export class SettingsService { this.removeSettings() } - this.authService.on("attempting-session", () => { - this.timer.start() - }) - this.authService.on("active-session", () => { this.timer.start() }) @@ -55,16 +50,16 @@ export class SettingsService { this.removeSettings() }) - if (this.authService.hasOrIsAcquiringActiveSession()) { + if (this.authService.hasActiveSession()) { this.timer.start() } } - private async fetchSettings(callback: () => void): Promise { + private async fetchSettings(callback: () => void): Promise { const token = this.authService.getSessionToken() if (!token) { - return + return false } try { @@ -76,7 +71,7 @@ export class SettingsService { if (!response.ok) { console.error(`Failed to fetch organization settings: ${response.status} ${response.statusText}`) - return + return false } const data = await response.json() @@ -84,7 +79,7 @@ export class SettingsService { if (!result.success) { console.error("Invalid organization settings format:", result.error) - return + return false } const newSettings = result.data @@ -94,8 +89,11 @@ export class SettingsService { await this.cacheSettings() callback() } + + return true } catch (error) { console.error("Error fetching organization settings:", error) + return false } }