Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import firebase from 'firebase'
  4.  
  5. const routerOptions = [
  6. { path: '/', component: 'Landing' },
  7. { path: '/signin', component: 'Signin' },
  8. { path: '/signup', component: 'Signup' },
  9. { path: '/home', component: 'Home', meta: { requiresAuth: true } },
  10. { path: '*', component: 'NotFound' }
  11. ]
  12.  
  13. const routes = routerOptions.map(route => {
  14. return {
  15. ...route,
  16. component: () => import(`@/components/${route.component}.vue`)
  17. }
  18. })
  19.  
  20. Vue.use(Router)
  21.  
  22. const router = new Router({
  23. mode: 'history',
  24. routes
  25. })
  26.  
  27. router.beforeEach((to, from, next) => {
  28. const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
  29. const isAuthenticated = firebase.auth().currentUser
  30. if (requiresAuth && !isAuthenticated) {
  31. next('/signin')
  32. } else {
  33. next()
  34. }
  35. })
  36.  
  37. export default router
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement