mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-07 14:09:59 +00:00
## Summary
Backport of #8350 to cloud/1.37
- Fix auth related race conditions with a new WorkspaceAuthGate in
App.vue
- De dup initialization calls
- Add state machine to track state of refreshRemoteConfig
- Fix websocket not using new workspace jwt
- Misc improvements
## Changes
Cherry-picked from commit 34fc28a39d
Resolved conflict in `src/views/GraphView.vue`:
- Kept workspace store initialization from cloud/1.37 branch
- Applied PR's refactored event listener pattern using
`useEventListener` from VueUse
- Applied PR's `useIntervalFn` for tab count tracking
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8357-backport-cloud-1-37-Feat-workspaces-5-auth-gate-check-2f66d73d365081bd8fe4f0cea481de11)
by [Unito](https://www.unito.io)
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { api } from '@/scripts/api'
|
|
|
|
import { remoteConfig, remoteConfigState } from './remoteConfig'
|
|
|
|
interface RefreshRemoteConfigOptions {
|
|
/**
|
|
* Whether to use authenticated API (default: true).
|
|
* Set to false during bootstrap before auth is initialized.
|
|
*/
|
|
useAuth?: boolean
|
|
}
|
|
|
|
/**
|
|
* Loads remote configuration from the backend /features endpoint
|
|
* and updates the reactive remoteConfig ref.
|
|
*
|
|
* Sets remoteConfigState to:
|
|
* - 'anonymous' when loaded without auth
|
|
* - 'authenticated' when loaded with auth
|
|
* - 'error' when load fails
|
|
*/
|
|
export async function refreshRemoteConfig(
|
|
options: RefreshRemoteConfigOptions = {}
|
|
): Promise<void> {
|
|
const { useAuth = true } = options
|
|
|
|
try {
|
|
const response = useAuth
|
|
? await api.fetchApi('/features', { cache: 'no-store' })
|
|
: await fetch('/api/features', { cache: 'no-store' })
|
|
|
|
if (response.ok) {
|
|
const config = await response.json()
|
|
window.__CONFIG__ = config
|
|
remoteConfig.value = config
|
|
remoteConfigState.value = useAuth ? 'authenticated' : 'anonymous'
|
|
return
|
|
}
|
|
|
|
console.warn('Failed to load remote config:', response.statusText)
|
|
if (response.status === 401 || response.status === 403) {
|
|
window.__CONFIG__ = {}
|
|
remoteConfig.value = {}
|
|
remoteConfigState.value = 'error'
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to fetch remote config:', error)
|
|
window.__CONFIG__ = {}
|
|
remoteConfig.value = {}
|
|
remoteConfigState.value = 'error'
|
|
}
|
|
}
|