Prechádzať zdrojové kódy

Fetch settings only when ready (#5052)

John Richmond 6 mesiacov pred
rodič
commit
9b40829922
1 zmenil súbory, kde vykonal 9 pridanie a 11 odobranie
  1. 9 11
      packages/cloud/src/SettingsService.ts

+ 9 - 11
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<void> {
+	private async fetchSettings(callback: () => void): Promise<boolean> {
 		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
 		}
 	}