useApplicationConfigTwoFactor.ts 1005 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { storeToRefs } from 'pinia'
  3. import { computed } from 'vue'
  4. import { useTwoFactorPlugins } from '#shared/entities/two-factor/composables/useTwoFactorPlugins.ts'
  5. import { useApplicationStore } from '#shared/stores/application.ts'
  6. const { twoFactorMethods } = useTwoFactorPlugins()
  7. export const useApplicationConfigTwoFactor = () => {
  8. const application = useApplicationStore()
  9. const { config } = storeToRefs(application)
  10. const twoFactorEnabledMethods = computed(() =>
  11. twoFactorMethods.filter(
  12. (method) =>
  13. config.value[`two_factor_authentication_method_${method.name}`],
  14. ),
  15. )
  16. const hasEnabledMethods = computed(() =>
  17. Boolean(twoFactorEnabledMethods.value.length),
  18. )
  19. const hasEnabledRecoveryCodes = computed(
  20. () => config.value.two_factor_authentication_recovery_codes,
  21. )
  22. return {
  23. hasEnabledMethods,
  24. hasEnabledRecoveryCodes,
  25. twoFactorEnabledMethods,
  26. }
  27. }