mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
[backport core/1.42] fix: gate cloud API calls behind Firebase authentication (#10877)
Backport of #9909 to `core/1.42` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10877-backport-core-1-42-fix-gate-cloud-API-calls-behind-Firebase-authentication-33a6d73d365081cfab7ce9b52d67d9eb) by [Unito](https://www.unito.io) Co-authored-by: Matt Miller <matt@miller-media.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
import { nextTick, ref } from 'vue'
|
||||
|
||||
import { useSettingStore } from '@/platform/settings/settingStore'
|
||||
|
||||
@@ -51,9 +51,11 @@ vi.mock('@/stores/userStore', () => ({
|
||||
}))
|
||||
|
||||
const mockIsFirebaseInitialized = ref(false)
|
||||
const mockIsFirebaseAuthenticated = ref(false)
|
||||
vi.mock('@/stores/firebaseAuthStore', () => ({
|
||||
useFirebaseAuthStore: vi.fn(() => ({
|
||||
isInitialized: mockIsFirebaseInitialized
|
||||
isInitialized: mockIsFirebaseInitialized,
|
||||
isAuthenticated: mockIsFirebaseAuthenticated
|
||||
}))
|
||||
}))
|
||||
|
||||
@@ -66,6 +68,7 @@ describe('bootstrapStore', () => {
|
||||
beforeEach(() => {
|
||||
mockIsSettingsReady.value = false
|
||||
mockIsFirebaseInitialized.value = false
|
||||
mockIsFirebaseAuthenticated.value = false
|
||||
mockNeedsLogin.value = false
|
||||
mockDistributionTypes.isCloud = false
|
||||
setActivePinia(createTestingPinia({ stubActions: false }))
|
||||
@@ -95,17 +98,23 @@ describe('bootstrapStore', () => {
|
||||
mockDistributionTypes.isCloud = true
|
||||
})
|
||||
|
||||
it('waits for Firebase auth before loading i18n and settings', async () => {
|
||||
it('waits for Firebase auth before loading stores', async () => {
|
||||
const store = useBootstrapStore()
|
||||
const settingStore = useSettingStore()
|
||||
const bootstrapPromise = store.startStoreBootstrap()
|
||||
|
||||
// Bootstrap is blocked waiting for firebase
|
||||
expect(store.isI18nReady).toBe(false)
|
||||
expect(settingStore.isReady).toBe(false)
|
||||
|
||||
// Unblock by initializing firebase
|
||||
// Firebase initialized but user not yet authenticated
|
||||
mockIsFirebaseInitialized.value = true
|
||||
await nextTick()
|
||||
|
||||
expect(store.isI18nReady).toBe(false)
|
||||
expect(settingStore.isReady).toBe(false)
|
||||
|
||||
// User authenticates (e.g. signs in on login page)
|
||||
mockIsFirebaseAuthenticated.value = true
|
||||
await bootstrapPromise
|
||||
|
||||
await vi.waitFor(() => {
|
||||
|
||||
@@ -36,14 +36,17 @@ export const useBootstrapStore = defineStore('bootstrap', () => {
|
||||
}
|
||||
|
||||
async function startStoreBootstrap() {
|
||||
if (isCloud) {
|
||||
const { isInitialized, isAuthenticated } = storeToRefs(
|
||||
useFirebaseAuthStore()
|
||||
)
|
||||
await until(isInitialized).toBe(true)
|
||||
await until(isAuthenticated).toBe(true)
|
||||
}
|
||||
|
||||
const userStore = useUserStore()
|
||||
await userStore.initialize()
|
||||
|
||||
if (isCloud) {
|
||||
const { isInitialized } = storeToRefs(useFirebaseAuthStore())
|
||||
await until(isInitialized).toBe(true)
|
||||
}
|
||||
|
||||
const { needsLogin } = storeToRefs(userStore)
|
||||
await until(needsLogin).toBe(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user