Skip to content

Commit cde49d5

Browse files
refresh feature flags on auth or subscription state change (#7197)
Adds watch on auth state that refreshes remote config. In future PR, the remote config system and feature flags should be consolidated and moved out of ComfyApi. Currently, we need feature flags before GraphView mounts, but also need to add auth headers after auth, which necessitates these parallel systems temporarily ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7197-refresh-feature-flags-on-auth-or-subscription-state-change-2c06d73d3650810a906ad36a60c86600) by [Unito](https://www.unito.io)
1 parent 5db6d1a commit cde49d5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/extensions/core/cloudRemoteConfig.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import { watchDebounced } from '@vueuse/core'
2+
3+
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
4+
import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription'
15
import { loadRemoteConfig } from '@/platform/remoteConfig/remoteConfig'
6+
import { refreshRemoteConfig } from '@/platform/remoteConfig/refreshRemoteConfig'
27
import { useExtensionService } from '@/services/extensionService'
38

49
/**
@@ -9,6 +14,18 @@ useExtensionService().registerExtension({
914
name: 'Comfy.Cloud.RemoteConfig',
1015

1116
setup: async () => {
17+
const { isLoggedIn } = useCurrentUser()
18+
const { isActiveSubscription } = useSubscription()
19+
20+
watchDebounced(
21+
[isLoggedIn, isActiveSubscription],
22+
() => {
23+
if (!isLoggedIn.value) return
24+
void refreshRemoteConfig()
25+
},
26+
{ debounce: 256, immediate: true }
27+
)
28+
1229
// Poll for config updates every 10 minutes
1330
setInterval(() => void loadRemoteConfig(), 600_000)
1431
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { api } from '@/scripts/api'
2+
3+
import { remoteConfig } from './remoteConfig'
4+
5+
export async function refreshRemoteConfig(): Promise<void> {
6+
try {
7+
const response = await api.fetchApi('/features', { cache: 'no-store' })
8+
if (response.ok) {
9+
const config = await response.json()
10+
window.__CONFIG__ = config
11+
remoteConfig.value = config
12+
return
13+
}
14+
15+
console.warn('Failed to load remote config:', response.statusText)
16+
if (response.status === 401 || response.status === 403) {
17+
window.__CONFIG__ = {}
18+
remoteConfig.value = {}
19+
}
20+
} catch (error) {
21+
console.error('Failed to fetch remote config:', error)
22+
}
23+
}

0 commit comments

Comments
 (0)