diff --git a/src/stores/bootstrapStore.test.ts b/src/stores/bootstrapStore.test.ts index ad85a4eaf..1fb36413c 100644 --- a/src/stores/bootstrapStore.test.ts +++ b/src/stores/bootstrapStore.test.ts @@ -42,10 +42,11 @@ vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ })) })) +const mockNeedsLogin = ref(false) vi.mock('@/stores/userStore', () => ({ useUserStore: vi.fn(() => ({ initialize: vi.fn().mockResolvedValue(undefined), - needsLogin: false + needsLogin: mockNeedsLogin })) })) @@ -65,6 +66,7 @@ describe('bootstrapStore', () => { beforeEach(() => { mockIsSettingsReady.value = false mockIsFirebaseInitialized.value = false + mockNeedsLogin.value = false mockDistributionTypes.isCloud = false setActivePinia(createTestingPinia({ stubActions: false })) vi.clearAllMocks() diff --git a/src/stores/bootstrapStore.ts b/src/stores/bootstrapStore.ts index 63eb00715..5b27f2ead 100644 --- a/src/stores/bootstrapStore.ts +++ b/src/stores/bootstrapStore.ts @@ -1,12 +1,12 @@ import { until, useAsyncState } from '@vueuse/core' import { defineStore, storeToRefs } from 'pinia' +import { isCloud } from '@/platform/distribution/types' import { useSettingStore } from '@/platform/settings/settingStore' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { api } from '@/scripts/api' -import { useUserStore } from '@/stores/userStore' -import { isCloud } from '@/platform/distribution/types' import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' +import { useUserStore } from '@/stores/userStore' export const useBootstrapStore = defineStore('bootstrap', () => { const settingStore = useSettingStore() @@ -26,9 +26,16 @@ export const useBootstrapStore = defineStore('bootstrap', () => { { immediate: false } ) + let storesLoaded = false + + function loadAuthenticatedStores() { + if (storesLoaded) return + storesLoaded = true + void settingStore.load() + void workflowStore.loadWorkflows() + } + async function startStoreBootstrap() { - // Defer settings and workflows if multi-user login is required - // (settings API requires authentication in multi-user mode) const userStore = useUserStore() await userStore.initialize() @@ -37,13 +44,11 @@ export const useBootstrapStore = defineStore('bootstrap', () => { await until(isInitialized).toBe(true) } - // i18n can load without authentication - void loadI18n() + const { needsLogin } = storeToRefs(userStore) + await until(needsLogin).toBe(false) - if (!userStore.needsLogin) { - void settingStore.load() - void workflowStore.loadWorkflows() - } + void loadI18n() + loadAuthenticatedStores() } return {