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
20 changes: 9 additions & 11 deletions packages/cloud/src/SettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
})
Expand All @@ -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 {
Expand All @@ -76,15 +71,15 @@ 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()
const result = organizationSettingsSchema.safeParse(data)

if (!result.success) {
console.error("Invalid organization settings format:", result.error)
return
return false
}

const newSettings = result.data
Expand All @@ -94,8 +89,11 @@ export class SettingsService {
await this.cacheSettings()
callback()
}

return true
} catch (error) {
console.error("Error fetching organization settings:", error)
return false
}
}

Expand Down
Loading