main.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Vue from 'vue'
  2. import './plugins/vuetify'
  3. import App from './App.vue'
  4. import router from './router'
  5. import store from './store'
  6. Vue.config.productionTip = false
  7. // A function loaded before each route change
  8. router.beforeEach((to, from, next) => {
  9. // Check if there is a special query in the URI
  10. if (to.query.q) {
  11. store.commit('setCustomLinkData', to.query.q)
  12. // GDPR notice not approved
  13. if (!store.getters.isGdprValidated) {
  14. if (to.name !== 'GdprNotice') return next('/gdpr')
  15. }
  16. return next('/experiments')
  17. }
  18. if (store.getters.isGdprValidated && store.state.customLinkData) {
  19. const request = JSON.parse(JSON.stringify(store.state.customLinkData)) // DEEP COPY
  20. store.commit('clearCustomLinkData')
  21. // Identify the user
  22. store.dispatch('setAppUniqueId')
  23. // Set the host configuration
  24. store.commit('setHostConfig', request.hostConfig)
  25. // Set the userId and experimentId (to explicitly identify the user)
  26. store.commit('setUserExperimentId', { userId: request.userId, experimentId: request.experimentId })
  27. // Redirect to the experiment scene selector (or directly to a scene if specified)
  28. if (request.experimentName) {
  29. if (request.sceneName)
  30. return next(`/experiments/${request.experimentName}/${request.sceneName}`)
  31. return next(`/experiments/${request.experimentName}/`)
  32. }
  33. return next()
  34. }
  35. // Redirect from config pages if already configured
  36. if (to.name === 'GdprNotice' && store.getters.isGdprValidated)
  37. return next('/hostConfig')
  38. if (to.path === '/hostConfig' && store.getters.isHostConfigured)
  39. return next('/experiments')
  40. // Redirect to configuration pages
  41. // Check GDPR before doing anything and redirect if necessary
  42. if (!store.getters.isGdprValidated) {
  43. if (to.name !== 'GdprNotice') return next('/gdpr')
  44. return next()
  45. }
  46. // Identify the user
  47. store.dispatch('setAppUniqueId')
  48. // Redirect if the host is not configured
  49. if (!store.getters.isHostConfigured) {
  50. if (to.path !== '/hostConfig')
  51. return next('/hostConfig')
  52. return next()
  53. }
  54. next()
  55. })
  56. new Vue({
  57. router,
  58. store,
  59. render: h => h(App)
  60. }).$mount('#app')