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
78 lines (65 loc) · 1.94 KB
/
Copy pathmain.js
File metadata and controls
78 lines (65 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
// Import ES6 Promise
import 'es6-promise/auto'
// Import System requirements
import Vue from 'vue'
import VueRouter from 'vue-router'
import { sync } from 'vuex-router-sync'
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)
Vue.use(VueRouter)
// Routing logic
var router = new VueRouter({
routes: routes,
mode: 'history',
linkExactActiveClass: 'active',
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) => {
if (
to.matched.some(record => record.meta.requiresAuth) &&
(!router.app.$store.state.token || router.app.$store.state.token === 'null')
) {
// this route requires auth, check if logged in
// if not, redirect to login page.
window.console.log('Not authenticated')
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
})
sync(store, router)
// Check local storage to handle refreshes
if (window.localStorage) {
var localUserString = window.localStorage.getItem('user') || 'null'
var localUser = JSON.parse(localUserString)
if (localUser && store.state.user !== localUser) {
store.commit('SET_USER', localUser)
store.commit('SET_TOKEN', window.localStorage.getItem('token'))
}
}
// Start out app!
// eslint-disable-next-line no-new
new Vue({
el: '#root',
router: router,
store: store,
render: h => h(AppView)
})
// change this. demo
window.bugsnagClient = window.bugsnag('02fe1c2caaf5874c50b6ee19534f5932')
window.bugsnagClient.use(window.bugsnag__vue(Vue))