diff --git a/packages/nc-gui-v2/composables/useGlobalState.ts b/packages/nc-gui-v2/composables/useGlobalState.ts index 2681ea5cd1..2c26623dd3 100644 --- a/packages/nc-gui-v2/composables/useGlobalState.ts +++ b/packages/nc-gui-v2/composables/useGlobalState.ts @@ -11,12 +11,12 @@ export const useGlobalState = (): GlobalState => { const preferredLanguages = $(usePreferredLanguages()) const darkMode = $(usePreferredDark()) - const initialState = { token: null, user: null, lang: preferredLanguages[0] || 'en', darkMode } + const initialState: State = { token: null, user: null, lang: preferredLanguages[0] || 'en', darkMode } const storage = useStorage(storageKey, initialState) // getters - const signedIn = computed(() => storage.value.token !== undefined && storage.value.user !== undefined) + const signedIn = computed(() => storage.value.token !== null && storage.value.token !== '' && storage.value.user !== null) // actions function signOut() { diff --git a/packages/nc-gui-v2/plugins/tele.ts b/packages/nc-gui-v2/plugins/tele.ts index 8a02189f9d..1b3d50e5ab 100644 --- a/packages/nc-gui-v2/plugins/tele.ts +++ b/packages/nc-gui-v2/plugins/tele.ts @@ -26,6 +26,10 @@ export default defineNuxtPlugin(async (nuxtApp) => { } catch {} } + if (nuxtApp.$state.signedIn.value) { + await init(nuxtApp.$state.token.value) + } + router.afterEach((to, from) => { if (!socket || (to.path === from.path && (to.query && to.query.type) === (from.query && from.query.type))) return @@ -77,8 +81,6 @@ export default defineNuxtPlugin(async (nuxtApp) => { } } - if (nuxtApp.$state.signedIn.value) await init(nuxtApp.$state.token.value) - watch((nuxtApp.$state as GlobalState).token, (newToken, oldToken) => { if (newToken && newToken !== oldToken) init(newToken) else if (!newToken) socket.disconnect()