main.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { createApp } from 'vue'
  3. import initializeApp from '#mobile/initialize.ts'
  4. import App from '#mobile/AppMobile.vue'
  5. import { useSessionStore } from '#shared/stores/session.ts'
  6. import initializeStoreSubscriptions from '#shared/initializer/storeSubscriptions.ts'
  7. import { useApplicationStore } from '#shared/stores/application.ts'
  8. import { useLocaleStore } from '#shared/stores/locale.ts'
  9. import initializeApolloClient from '#mobile/server/apollo/index.ts'
  10. import initializeRouter from '#mobile/router/index.ts'
  11. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  12. import { useForceDesktop } from '#shared/composables/useForceDesktop.ts'
  13. import { ensureAfterAuth } from './pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  14. const { forceDesktopLocalStorage } = useForceDesktop()
  15. // If the user explicitly switched to the desktop app the last time around,
  16. // redirect them automatically, before hoisting the app.
  17. if (forceDesktopLocalStorage.value) window.location.href = '/'
  18. export default async function mountApp(): Promise<void> {
  19. const app = createApp(App)
  20. const router = initializeRouter(app)
  21. Object.defineProperty(window, 'Router', { value: router, configurable: true })
  22. initializeApp(app)
  23. initializeApolloClient(app)
  24. initializeStoreSubscriptions()
  25. const session = useSessionStore()
  26. const authentication = useAuthenticationStore()
  27. // If the session is invalid, clear the already set authentication flag from storage.
  28. if (!(await session.checkSession()) && authentication.authenticated) {
  29. authentication.authenticated = false
  30. }
  31. const application = useApplicationStore()
  32. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  33. application.getConfig(),
  34. ]
  35. if (session.id) {
  36. authentication.authenticated = true
  37. initalizeAfterSessionCheck.push(session.getCurrentUser())
  38. }
  39. await Promise.all(initalizeAfterSessionCheck)
  40. if (session.id) session.initialized = true
  41. const locale = useLocaleStore()
  42. if (!locale.localeData) {
  43. await locale.setLocale()
  44. }
  45. if (VITE_TEST_MODE) {
  46. await import('#shared/initializer/initializeFakeTimer.ts')
  47. }
  48. app.mount('#app')
  49. if (session.afterAuth) {
  50. await ensureAfterAuth(router, session.afterAuth)
  51. }
  52. }