callback.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <NuxtLayout name="blank">
  3. <v-app>
  4. <div class="d-flex flex-column align-center justify-center fill-height">
  5. <v-progress-circular indeterminate size="64" />
  6. <span class="mt-3">{{ $t('please_wait') }}</span>
  7. </div>
  8. </v-app>
  9. </NuxtLayout>
  10. </template>
  11. <script setup lang="ts">
  12. /**
  13. * Disable the default layout, the page will use the layout defined with <NuxtLayout />
  14. * @see https://nuxt.com/docs/guide/directory-structure/layouts#overriding-a-layout-on-a-per-page-basis
  15. */
  16. import type { RouteLocationNormalizedLoaded } from 'vue-router'
  17. import { useEntityManager } from '~/composables/data/useEntityManager'
  18. import ConnectionRequest from '~/models/ApiResources/HelloAsso/ConnectionRequest'
  19. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  20. definePageMeta({
  21. name: 'helloasso_callback_page',
  22. layout: false,
  23. })
  24. const organizationProfile = useOrganizationProfileStore()
  25. const { em } = useEntityManager()
  26. const route: RouteLocationNormalizedLoaded = useRoute()
  27. if (!route.query.code) {
  28. throw new Error('Missing parameter')
  29. }
  30. const authorizationCode: Ref<string> = ref(route.query.code as string)
  31. const connectionRequest: ConnectionRequest = em.newInstance(
  32. ConnectionRequest,
  33. {
  34. organizationId: organizationProfile.id,
  35. authorizationCode: authorizationCode.value,
  36. },
  37. )
  38. onMounted(async () => {
  39. await em.persist(connectionRequest)
  40. console.log('Connection request created')
  41. // Send a event to the parent window to notify the connection request has been created (in case SSE is not available)
  42. window.opener?.postMessage(
  43. { code: authorizationCode.value },
  44. window.location.origin,
  45. )
  46. // Close the popup
  47. window.close()
  48. })
  49. </script>
  50. <style scoped lang="scss"></style>