Skip to content

Instantly share code, notes, and snippets.

@Mattchewone
Created June 15, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattchewone/23ad22d0614ba80dd4129985cb056267 to your computer and use it in GitHub Desktop.
Save Mattchewone/23ad22d0614ba80dd4129985cb056267 to your computer and use it in GitHub Desktop.
Default Vue main.js file
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
const currentUser = store.state.auth.user
const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
if (requiresAuth && !currentUser) {
next('/login')
} else {
next()
}
})
// Auth first before loading the app
store.dispatch('auth/authenticate')
.catch(() => {})
// Render the app
.then(() => {
// eslint-disable-next-line no-new
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment