This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
/
app.js
87 lines (74 loc) · 2.28 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Vue from 'vue'
import './config-check'
import './console-splash'
import './filters'
import './plugins'
import './mixins'
import './components'
import store from './store'
import router from './router'
import { i18n } from '@cortezaproject/corteza-vue'
export default (options = {}) => {
options = {
el: '#app',
name: 'workflow',
template: '<div v-if="loaded && i18nLoaded" class="h-100"><router-view/></div>',
data: () => ({
loaded: false,
i18nLoaded: false,
}),
async created () {
this.$i18n.i18next.on('loaded', () => {
this.i18nLoaded = true
})
return this.$auth.vue(this).handle().then(({ accessTokenFn, user }) => {
if (user.meta.preferredLanguage) {
// After user is authenticated, get his preferred language
// and instruct i18next to change it
this.$i18n.i18next.changeLanguage(user.meta.preferredLanguage)
}
// Load effective permissions
this.$store.dispatch('rbac/load')
this.$Settings.init({ api: this.$SystemAPI }).then(() => {
this.loaded = true
// This bit removes code from the query params
//
// Vue router can't be used here because when on any child route there is no
// guarantee that the route has loaded and so it may redirect us to the root page.
//
// @todo dig a bit deeper if there is a better vue-like solution; atm none were ok.
const url = new URL(window.location.href)
if (url.searchParams.get('code')) {
url.searchParams.delete('code')
window.location.replace(url.toString())
}
})
}).catch((err) => {
if (err instanceof Error && err.message === 'Unauthenticated') {
// user not logged-in,
// start with authentication flow
this.$auth.startAuthenticationFlow()
return
}
throw err
})
},
router,
store,
i18n: i18n(Vue,
{ app: 'corteza-webapp-workflow' },
'configurator',
'editor',
'help',
'general',
'navigation',
'notification',
'permissions',
'configurator',
'steps',
),
// Any additional options we want to merge
...options,
}
return new Vue(options)
}