AppDesktop.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import useFormKitConfig from '#shared/composables/form/useFormKitConfig.ts'
  4. import CommonNotifications from '#shared/components/CommonNotifications/CommonNotifications.vue'
  5. import useAppMaintenanceCheck from '#shared/composables/useAppMaintenanceCheck.ts'
  6. import useAuthenticationChanges from '#shared/composables/authentication/useAuthenticationUpdates.ts'
  7. import useMetaTitle from '#shared/composables/useMetaTitle.ts'
  8. import usePushMessages from '#shared/composables/usePushMessages.ts'
  9. import { useApplicationStore } from '#shared/stores/application.ts'
  10. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  11. import { useLocaleStore } from '#shared/stores/locale.ts'
  12. import emitter from '#shared/utils/emitter.ts'
  13. import { onBeforeMount, onBeforeUnmount } from 'vue'
  14. import { useRouter } from 'vue-router'
  15. const router = useRouter()
  16. const authentication = useAuthenticationStore()
  17. useMetaTitle().initializeMetaTitle()
  18. const application = useApplicationStore()
  19. onBeforeMount(() => {
  20. application.setLoaded()
  21. })
  22. useAppMaintenanceCheck()
  23. usePushMessages()
  24. // Add a check for authenticated changes (e.g. login/logout in a other
  25. // browser tab or maintenance mode switch).
  26. useAuthenticationChanges()
  27. // We need to trigger a manual translation update for the form related strings.
  28. const formConfig = useFormKitConfig()
  29. useLocaleStore().$subscribe(() => {
  30. formConfig.locale = 'staticLocale'
  31. })
  32. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  33. // response is received.
  34. emitter.on('sessionInvalid', async () => {
  35. if (authentication.authenticated) {
  36. await authentication.clearAuthentication()
  37. router.replace({
  38. name: 'Login',
  39. query: {
  40. invalidatedSession: '1',
  41. },
  42. })
  43. }
  44. })
  45. // Initialize the ticket overview store after a valid session is present on
  46. // the app level, so that the query keeps alive.
  47. // watch(
  48. // () => session.initialized,
  49. // (newValue, oldValue) => {
  50. // if (!oldValue && newValue) {
  51. // useTicketOverviewsStore()
  52. // }
  53. // },
  54. // { immediate: true },
  55. // )
  56. onBeforeUnmount(() => {
  57. emitter.off('sessionInvalid')
  58. })
  59. </script>
  60. <template>
  61. <template v-if="application.loaded">
  62. <CommonNotifications />
  63. </template>
  64. <RouterView v-if="application.loaded" />
  65. </template>