main.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // update experiment progress due to perhaps new ids
  28. store.commit('updateExperimentProgress')
  29. // Redirect to the experiment scene selector (or directly to a scene if specified)
  30. if (request.experimentName) {
  31. if (request.sceneName)
  32. return next(`/experiments/${request.experimentName}/${request.sceneName}`)
  33. return next(`/experiments/${request.experimentName}/`)
  34. }
  35. return next()
  36. }
  37. // Redirect from config pages if already configured
  38. if (to.name === 'GdprNotice' && store.getters.isGdprValidated)
  39. return next('/hostConfig')
  40. if (to.path === '/hostConfig' && store.getters.isHostConfigured)
  41. return next('/experiments')
  42. // Redirect to configuration pages
  43. // Check GDPR before doing anything and redirect if necessary
  44. if (!store.getters.isGdprValidated) {
  45. if (to.name !== 'GdprNotice') return next('/gdpr')
  46. return next()
  47. }
  48. // Identify the user
  49. store.dispatch('setAppUniqueId')
  50. // Redirect if the host is not configured
  51. if (!store.getters.isHostConfigured) {
  52. if (to.path !== '/hostConfig')
  53. return next('/hostConfig')
  54. return next()
  55. }
  56. next()
  57. })
  58. new Vue({
  59. router,
  60. store,
  61. render: h => h(App)
  62. }).$mount('#app')