main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. import VueNativeSock from 'vue-native-websocket'
  7. Vue.config.productionTip = false
  8. // Connect the WebSocket client to the store
  9. Vue.use(VueNativeSock, 'ws://example.com', {
  10. store,
  11. connectManually: true,
  12. reconnection: true,
  13. reconnectionAttempts: 2,
  14. reconnectionDelay: 1000
  15. })
  16. store.$socket = Vue.prototype.$socket
  17. // A function loaded before each route change
  18. router.beforeEach((to, from, next) => {
  19. // Redirect from config pages if already configured
  20. if (to.path === '/gdpr' && store.getters.isGdprValidated)
  21. return next('/hostConfig')
  22. if (to.path === '/hostConfig' && store.getters.isHostConfigured)
  23. return next('/experiments')
  24. // Redirect to configuration pages
  25. // Check GDPR before doing anything and redirect if necessary
  26. if (!store.getters.isGdprValidated) {
  27. if (to.path !== '/gdpr') return next('/gdpr')
  28. return next()
  29. }
  30. // Identify the user
  31. store.dispatch('setAppUniqueId')
  32. // Redirect if the host is not configured
  33. if (!store.getters.isHostConfigured) {
  34. if (to.path !== '/hostConfig')
  35. return next('/hostConfig')
  36. return next()
  37. }
  38. next()
  39. })
  40. new Vue({
  41. router,
  42. store,
  43. render: h => h(App)
  44. }).$mount('#app')