forked from misterGF/CoPilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
80 lines (66 loc) · 1.94 KB
/
Copy pathmain.js
File metadata and controls
80 lines (66 loc) · 1.94 KB
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
// Import System requirements
import Vue from 'vue'
import Resource from 'vue-resource'
import VueRouter from 'vue-router'
import routes from './routes'
import store from './store'
// Import Helpers for filters
import { domain, count, prettyDate, pluralize } from './filters'
// Import Views - Top level
import AppView from './components/App.vue'
// Import Install and register helper items
Vue.filter('count', count)
Vue.filter('domain', domain)
Vue.filter('prettyDate', prettyDate)
Vue.filter('pluralize', pluralize)
// Resource logic
Vue.use(Resource)
Vue.use(VueRouter)
Vue.http.interceptors.push((request, next) => {
/*
Enable this when you have a backend that you authenticate against
var headers = request.headers
if (window.location.pathname !== '/login' && !headers.hasOwnProperty('Authorization')) {
headers.Authorization = this.$store.state.token
}
*/
// console.log(headers)
// continue to next interceptor without modifying the response
next()
})
// Routing logic
var router = new VueRouter({
routes: routes,
mode: 'history',
scrollBehavior: function (to, from, savedPosition) {
return savedPosition || { x: 0, y: 0 }
}
})
// Some middleware to help us ensure the user is authenticated.
router.beforeEach((to, from, next) => {
// window.console.log('Transition', transition)
if (to.auth && (to.router.app.$store.state.token === 'null')) {
window.console.log('Not authenticated')
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
})
// Start out app!
// eslint-disable-next-line no-new
new Vue({
el: '#root',
router: router,
store: store,
render: h => h(AppView)
})
// Check local storage to handle refreshes
if (window.localStorage) {
if (store.state.user !== window.localStorage.getItem('user')) {
store.commit('SET_USER', JSON.parse(window.localStorage.getItem('user')))
store.commit('SET_TOKEN', window.localStorage.getItem('token'))
}
}