mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
63 lines
1.4 KiB
JavaScript
Executable File
63 lines
1.4 KiB
JavaScript
Executable File
import Vue from 'vue'
|
|
import DashboardPlugin from './plugins/dashboard-plugin'
|
|
import App from './App.vue'
|
|
import i18n from './i18n.js'
|
|
import { loadAllRules } from './validation-rules'
|
|
import { ApolloClient, ApolloLink, InMemoryCache, HttpLink } from 'apollo-boost'
|
|
import VueApollo from 'vue-apollo'
|
|
import CONFIG from './config'
|
|
|
|
import { store } from './store/store'
|
|
|
|
import router from './routes/router'
|
|
|
|
const httpLink = new HttpLink({ uri: CONFIG.GRAPHQL_URI })
|
|
|
|
const authLink = new ApolloLink((operation, forward) => {
|
|
const token = store.state.token
|
|
operation.setContext({
|
|
headers: {
|
|
Authorization: token && token.length > 0 ? `Bearer ${token}` : '',
|
|
},
|
|
})
|
|
return forward(operation).map((response) => {
|
|
const newToken = operation.getContext().response.headers.get('token')
|
|
if (newToken) store.commit('token', newToken)
|
|
return response
|
|
})
|
|
})
|
|
|
|
const apolloClient = new ApolloClient({
|
|
link: authLink.concat(httpLink),
|
|
cache: new InMemoryCache(),
|
|
uri: CONFIG.GRAPHQL_URI,
|
|
})
|
|
|
|
const apolloProvider = new VueApollo({
|
|
defaultClient: apolloClient,
|
|
})
|
|
|
|
// plugin setup
|
|
Vue.use(DashboardPlugin)
|
|
Vue.config.productionTip = false
|
|
|
|
loadAllRules(i18n)
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.meta.requiresAuth && !store.state.token) {
|
|
next({ path: '/login' })
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
/* eslint-disable no-new */
|
|
new Vue({
|
|
el: '#app',
|
|
router,
|
|
store,
|
|
i18n,
|
|
apolloProvider,
|
|
render: (h) => h(App),
|
|
})
|