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)
This commit is contained in:
Christian Byrne
2025-12-05 18:40:11 -08:00
committed by GitHub
parent 5db6d1af9a
commit cde49d5b64
2 changed files with 40 additions and 0 deletions

View File

@@ -1,4 +1,9 @@
import { watchDebounced } from '@vueuse/core'
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription'
import { loadRemoteConfig } from '@/platform/remoteConfig/remoteConfig'
import { refreshRemoteConfig } from '@/platform/remoteConfig/refreshRemoteConfig'
import { useExtensionService } from '@/services/extensionService'
/**
@@ -9,6 +14,18 @@ useExtensionService().registerExtension({
name: 'Comfy.Cloud.RemoteConfig',
setup: async () => {
const { isLoggedIn } = useCurrentUser()
const { isActiveSubscription } = useSubscription()
watchDebounced(
[isLoggedIn, isActiveSubscription],
() => {
if (!isLoggedIn.value) return
void refreshRemoteConfig()
},
{ debounce: 256, immediate: true }
)
// Poll for config updates every 10 minutes
setInterval(() => void loadRemoteConfig(), 600_000)
}

View File

@@ -0,0 +1,23 @@
import { api } from '@/scripts/api'
import { remoteConfig } from './remoteConfig'
export async function refreshRemoteConfig(): Promise<void> {
try {
const response = await api.fetchApi('/features', { cache: 'no-store' })
if (response.ok) {
const config = await response.json()
window.__CONFIG__ = config
remoteConfig.value = config
return
}
console.warn('Failed to load remote config:', response.statusText)
if (response.status === 401 || response.status === 403) {
window.__CONFIG__ = {}
remoteConfig.value = {}
}
} catch (error) {
console.error('Failed to fetch remote config:', error)
}
}