{"size": 1294, "ext": "js", "max_stars_repo_path": "frontend/wc/src/router/index.js", "max_stars_repo_name": "powerblossom/workcloud", "max_stars_repo_stars_event_min_datetime": "2019-10-18T05:57:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-18T05:57:13.000Z", "max_issues_repo_path": "frontend/wc/src/router/index.js", "max_issues_repo_name": "powerblossom/workcloud", "max_issues_repo_issues_event_min_datetime": "2019-12-02T13:59:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T08:52:19.000Z", "max_forks_repo_path": "frontend/wc/src/router/index.js", "max_forks_repo_name": "powerblossom/workcloud", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 11, "max_forks_count": null, "avg_line_length": 18.7536231884, "max_line_length": 60, "alphanum_fraction": 0.5687789799}
import Vue from 'vue'
import VueRouter from 'vue-router'

import AccountsRoutes from '@/router/accounts'
import CommunitiesRoutes from '@/router/communities'
import ThingsRoutes from '@/router/things'

import { store } from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'landing',
    component: () => import('@/views/Landing.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/Search.vue')
  },
  {
    path: '/manage',
    name: 'manage',
    meta: { requiresAuth: true, StaffOnly: true },
    component: () => import('@/views/Manage.vue')
  },
  ...AccountsRoutes,
  ...CommunitiesRoutes,
  ...ThingsRoutes,
]

const router = new VueRouter({
  routes,
})

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!store.getters.isApproved) {
      next({
        name: 'accounts.login',
        query: {
          nextURL: to.path
        }
      })
    }
    else if (
      to.matched.some(record => record.meta.StaffOnly) &&
      !store.getters.isStaff
    ) {
      next(false)
    }
    else {
      next()
    }
  }
  else {
    next()
  }
})

export default router
