callback.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!--
  2. Page cible du callback après authentification via la mire d'autorisation HelloAsso
  3. @see https://dev.helloasso.com/docs/mire-authorisation
  4. -->
  5. <template>
  6. <NuxtLayout name="blank">
  7. <v-app>
  8. <div
  9. v-if="!error"
  10. class="d-flex flex-column align-center justify-center fill-height theme-secondary"
  11. >
  12. <v-progress-circular indeterminate size="64" />
  13. <span class="mt-3"> {{ $t('please_wait') }}... </span>
  14. </div>
  15. <div v-else class="ma-4">
  16. <div>{{ $t('an_error_occured')}}</div>
  17. <div>{{ $t('please_contact_support')}}</div>
  18. </div>
  19. </v-app>
  20. </NuxtLayout>
  21. </template>
  22. <script setup lang="ts">
  23. /**
  24. * Disable the default layout, the page will use the layout defined with <NuxtLayout />
  25. * @see https://nuxt.com/docs/guide/directory-structure/layouts#overriding-a-layout-on-a-per-page-basis
  26. */
  27. import type { RouteLocationNormalizedLoaded } from 'vue-router'
  28. import { useEntityManager } from '~/composables/data/useEntityManager'
  29. import ConnectionRequest from '~/models/HelloAsso/ConnectionRequest'
  30. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  31. definePageMeta({
  32. name: 'helloasso_callback_page',
  33. layout: false,
  34. })
  35. const organizationProfile = useOrganizationProfileStore()
  36. const { em } = useEntityManager()
  37. const route: RouteLocationNormalizedLoaded = useRoute()
  38. if (!route.query.code) {
  39. throw new Error('Missing parameter')
  40. }
  41. const authorizationCode: Ref<string> = ref(route.query.code as string)
  42. const connectionRequest: ConnectionRequest = em.newInstance(
  43. ConnectionRequest,
  44. {
  45. organizationId: organizationProfile.id,
  46. authorizationCode: authorizationCode.value,
  47. },
  48. )
  49. const error: Ref<boolean> = ref(false)
  50. onMounted(async () => {
  51. try {
  52. await em.persist(connectionRequest)
  53. } catch (e) {
  54. error.value = true
  55. throw e
  56. }
  57. // Send a event to the parent window to notify the connection request has been created (in case SSE is not available)
  58. window.opener?.postMessage(
  59. { code: authorizationCode.value },
  60. window.location.origin,
  61. )
  62. // Close the popup
  63. window.close()
  64. })
  65. </script>
  66. <style scoped lang="scss">
  67. .background {
  68. background-color: var(--v-theme-secondary);
  69. }
  70. </style>