fix: await needsLogin (#8340)

## Summary

Add additional protection for bootstrap order issues.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8340-fix-await-needsLogin-2f56d73d365081c9b3c6d5a091c1eb8d)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-01-27 14:04:35 -08:00
committed by GitHub
parent 50461d401a
commit bcb4d6e403
2 changed files with 18 additions and 11 deletions

View File

@@ -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()

View File

@@ -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 {