Skip to content

Commit 1c4ff1a

Browse files
committed
fix: await needsLogin
1 parent 50461d4 commit 1c4ff1a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/stores/bootstrapStore.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { until, useAsyncState } from '@vueuse/core'
22
import { defineStore, storeToRefs } from 'pinia'
33

4+
import { isCloud } from '@/platform/distribution/types'
45
import { useSettingStore } from '@/platform/settings/settingStore'
56
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
67
import { api } from '@/scripts/api'
7-
import { useUserStore } from '@/stores/userStore'
8-
import { isCloud } from '@/platform/distribution/types'
98
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
9+
import { useUserStore } from '@/stores/userStore'
1010

1111
export const useBootstrapStore = defineStore('bootstrap', () => {
1212
const settingStore = useSettingStore()
@@ -26,9 +26,16 @@ export const useBootstrapStore = defineStore('bootstrap', () => {
2626
{ immediate: false }
2727
)
2828

29+
let storesLoaded = false
30+
31+
function loadAuthenticatedStores() {
32+
if (storesLoaded) return
33+
storesLoaded = true
34+
void settingStore.load()
35+
void workflowStore.loadWorkflows()
36+
}
37+
2938
async function startStoreBootstrap() {
30-
// Defer settings and workflows if multi-user login is required
31-
// (settings API requires authentication in multi-user mode)
3239
const userStore = useUserStore()
3340
await userStore.initialize()
3441

@@ -37,13 +44,11 @@ export const useBootstrapStore = defineStore('bootstrap', () => {
3744
await until(isInitialized).toBe(true)
3845
}
3946

40-
// i18n can load without authentication
41-
void loadI18n()
47+
const { needsLogin } = storeToRefs(userStore)
48+
await until(needsLogin).toBe(false)
4249

43-
if (!userStore.needsLogin) {
44-
void settingStore.load()
45-
void workflowStore.loadWorkflows()
46-
}
50+
void loadI18n()
51+
loadAuthenticatedStores()
4752
}
4853

4954
return {

0 commit comments

Comments
 (0)