AltchaValidation.client.vue 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <altcha-widget
  3. v-show="widget !== null"
  4. ref="widget"
  5. :challengeurl="runtimeConfig.public.challengeUrl"
  6. debug
  7. />
  8. </template>
  9. <script setup lang="ts">
  10. import { ref, onMounted, onUnmounted, type Ref } from 'vue'
  11. import 'altcha'
  12. import { useRuntimeConfig } from 'nuxt/app'
  13. const runtimeConfig = useRuntimeConfig()
  14. const widget: Ref<HTMLElement | null> = ref(null)
  15. const emit = defineEmits(['verified'])
  16. const onStateChange = (e: CustomEvent | Event) => {
  17. if ('detail' in e) {
  18. const { payload, state } = e.detail
  19. if (state === 'verified' && payload) {
  20. emit('verified')
  21. }
  22. }
  23. }
  24. onMounted(() => {
  25. setTimeout(() => {
  26. if (widget.value) {
  27. widget.value.addEventListener('statechange', onStateChange)
  28. }
  29. }, 10)
  30. })
  31. onUnmounted(() => {
  32. if (widget.value) {
  33. widget.value.removeEventListener('statechange', onStateChange)
  34. }
  35. })
  36. </script>
  37. <style scoped lang="scss">
  38. </style>