2018-11-27 10:51:33 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Router from 'vue-router';
|
|
|
|
import ROUTES from '@/utils/constants/routerConstants';
|
|
|
|
import Login from '@/views/Login.vue';
|
|
|
|
import Register from '@/views/Register.vue';
|
2018-11-14 14:00:01 +00:00
|
|
|
import Dashboard from '@/views/Dashboard.vue';
|
|
|
|
import AccountArea from '@/components/dashboard/account/AccountArea.vue';
|
2018-11-23 15:48:11 +00:00
|
|
|
import ProjectDetails from '@/components/projectDetails/ProjectDetailsArea.vue';
|
2018-12-05 16:39:03 +00:00
|
|
|
import TeamArea from '@/components/team/TeamArea.vue';
|
2018-12-12 10:06:33 +00:00
|
|
|
import Page404 from '@/components/errors/Page404.vue';
|
2019-01-02 13:46:55 +00:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2018-12-18 14:43:23 +00:00
|
|
|
import { getToken } from '@/utils/tokenManager';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
Vue.use(Router);
|
|
|
|
|
2018-12-05 16:39:03 +00:00
|
|
|
let router = new Router({
|
|
|
|
mode: 'history',
|
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: ROUTES.LOGIN.path,
|
|
|
|
name: ROUTES.LOGIN.name,
|
|
|
|
component: Login
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.REGISTER.path,
|
|
|
|
name: ROUTES.REGISTER.name,
|
|
|
|
component: Register
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.DASHBOARD.path,
|
|
|
|
name: ROUTES.DASHBOARD.name,
|
2018-12-12 16:19:20 +00:00
|
|
|
meta: {
|
|
|
|
requiresAuth: true
|
|
|
|
},
|
2018-12-05 16:39:03 +00:00
|
|
|
component: Dashboard,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '/account-settings',
|
|
|
|
name: 'AccountSettings',
|
|
|
|
component: AccountArea
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/project-details',
|
|
|
|
name: 'ProjectDetails',
|
|
|
|
component: ProjectDetails
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/team',
|
|
|
|
name: 'Team',
|
|
|
|
component: TeamArea
|
2019-01-02 13:46:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/api-keys',
|
|
|
|
name: 'ApiKeys',
|
|
|
|
component: ApiKeysArea
|
2018-12-05 16:39:03 +00:00
|
|
|
}
|
|
|
|
]
|
2018-12-12 10:06:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '*',
|
|
|
|
name: '404',
|
|
|
|
component: Page404
|
2018-12-05 16:39:03 +00:00
|
|
|
}
|
2018-12-12 16:19:20 +00:00
|
|
|
]
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
2018-11-28 09:16:35 +00:00
|
|
|
|
|
|
|
// Makes check that Token exist at session storage before any route except Login and Register
|
|
|
|
router.beforeEach((to, from, next) => {
|
2018-12-18 14:43:23 +00:00
|
|
|
if (to.matched.some(route => route.meta.requiresAuth)) {
|
2018-12-12 16:19:20 +00:00
|
|
|
if (!getToken()) {
|
|
|
|
next(ROUTES.LOGIN);
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2018-12-12 16:19:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 09:16:35 +00:00
|
|
|
|
2018-12-12 16:19:20 +00:00
|
|
|
next();
|
2018-11-28 09:16:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|