2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// 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';
|
2019-04-01 12:24:45 +01:00
|
|
|
import Login from '@/views/login/Login.vue';
|
|
|
|
import Register from '@/views/register/Register.vue';
|
2019-04-02 14:38:57 +01:00
|
|
|
import ForgotPassword from '@/views/forgotPassword/ForgotPassword.vue';
|
2018-11-14 14:00:01 +00:00
|
|
|
import Dashboard from '@/views/Dashboard.vue';
|
2019-01-09 15:40:21 +00:00
|
|
|
import AccountArea from '@/components/account/AccountArea.vue';
|
2019-06-03 13:19:48 +01:00
|
|
|
import Profile from '@/components/account/Profile.vue';
|
|
|
|
import AccountBillingHistory from '@/components/account/billing/BillingArea.vue';
|
|
|
|
import AccountPaymentMethods from '@/components/account/AccountPaymentMethods.vue';
|
2019-05-15 16:01:41 +01:00
|
|
|
import ProjectOverviewArea from '@/components/project/ProjectOverviewArea.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';
|
2019-04-02 20:33:03 +01:00
|
|
|
import UsageReport from '@/components/project/UsageReport.vue';
|
2019-05-15 16:01:41 +01:00
|
|
|
import ProjectDetails from '@/components/project/ProjectDetails.vue';
|
2019-06-03 13:19:48 +01:00
|
|
|
import ProjectBillingHistory from '@/components/project/billing/BillingArea.vue';
|
|
|
|
import ProjectPaymentMethods from '@/components/project/ProjectPaymentMethods.vue';
|
2019-03-14 12:48:43 +00:00
|
|
|
import BucketArea from '@/components/buckets/BucketArea.vue';
|
2019-07-22 10:46:26 +01:00
|
|
|
import { AuthToken } from '@/utils/authToken';
|
2019-04-05 16:08:14 +01:00
|
|
|
import store from '@/store';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
Vue.use(Router);
|
|
|
|
|
2018-12-05 16:39:03 +00:00
|
|
|
let router = new Router({
|
2019-02-20 13:33:56 +00:00
|
|
|
mode: 'history',
|
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: ROUTES.LOGIN.path,
|
|
|
|
name: ROUTES.LOGIN.name,
|
|
|
|
component: Login
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.REGISTER.path,
|
|
|
|
name: ROUTES.REGISTER.name,
|
|
|
|
component: Register
|
|
|
|
},
|
2019-07-19 19:22:10 +01:00
|
|
|
{
|
|
|
|
path: ROUTES.REFERRAL.path,
|
|
|
|
name: ROUTES.REFERRAL.name,
|
|
|
|
component: Register
|
|
|
|
},
|
2019-04-02 14:38:57 +01:00
|
|
|
{
|
|
|
|
path: ROUTES.FORGOT_PASSWORD.path,
|
|
|
|
name: ROUTES.FORGOT_PASSWORD.name,
|
|
|
|
component: ForgotPassword
|
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
{
|
|
|
|
path: ROUTES.DASHBOARD.path,
|
|
|
|
meta: {
|
|
|
|
requiresAuth: true
|
|
|
|
},
|
|
|
|
component: Dashboard,
|
|
|
|
children: [
|
|
|
|
{
|
2019-02-21 14:14:18 +00:00
|
|
|
path: ROUTES.ACCOUNT_SETTINGS.path,
|
|
|
|
name: ROUTES.ACCOUNT_SETTINGS.name,
|
2019-06-03 13:19:48 +01:00
|
|
|
component: AccountArea,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: ROUTES.PROFILE.path,
|
|
|
|
name: ROUTES.PROFILE.name,
|
|
|
|
component: Profile,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.PAYMENT_METHODS.path,
|
|
|
|
name: ROUTES.PAYMENT_METHODS.name,
|
|
|
|
component: AccountPaymentMethods,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.BILLING_HISTORY.path,
|
|
|
|
name: ROUTES.BILLING_HISTORY.name,
|
|
|
|
component: AccountBillingHistory,
|
|
|
|
},
|
|
|
|
]
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-05-15 16:01:41 +01:00
|
|
|
path: ROUTES.PROJECT_OVERVIEW.path,
|
|
|
|
name: ROUTES.PROJECT_OVERVIEW.name,
|
|
|
|
component: ProjectOverviewArea,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: ROUTES.USAGE_REPORT.path,
|
|
|
|
name: ROUTES.USAGE_REPORT.name,
|
|
|
|
component: UsageReport,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.PROJECT_DETAILS.path,
|
|
|
|
name: ROUTES.PROJECT_DETAILS.name,
|
|
|
|
component: ProjectDetails
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.BILLING_HISTORY.path,
|
|
|
|
name: ROUTES.BILLING_HISTORY.name,
|
2019-06-03 13:19:48 +01:00
|
|
|
component: ProjectBillingHistory
|
2019-05-15 16:01:41 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ROUTES.PAYMENT_METHODS.path,
|
|
|
|
name: ROUTES.PAYMENT_METHODS.name,
|
2019-06-03 13:19:48 +01:00
|
|
|
component: ProjectPaymentMethods
|
2019-05-15 16:01:41 +01:00
|
|
|
},
|
|
|
|
]
|
2019-04-05 16:08:14 +01:00
|
|
|
},
|
|
|
|
// Remove when dashboard will be created
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'default',
|
2019-05-15 16:01:41 +01:00
|
|
|
component: ProjectOverviewArea
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-21 14:14:18 +00:00
|
|
|
path: ROUTES.TEAM.path,
|
|
|
|
name: ROUTES.TEAM.name,
|
2019-02-20 13:33:56 +00:00
|
|
|
component: TeamArea
|
|
|
|
},
|
|
|
|
{
|
2019-02-21 14:14:18 +00:00
|
|
|
path: ROUTES.API_KEYS.path,
|
|
|
|
name: ROUTES.API_KEYS.name,
|
2019-02-20 13:33:56 +00:00
|
|
|
component: ApiKeysArea
|
|
|
|
},
|
2019-05-16 11:43:46 +01:00
|
|
|
{
|
|
|
|
path: ROUTES.BUCKETS.path,
|
|
|
|
name: ROUTES.BUCKETS.name,
|
|
|
|
component: BucketArea
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
// {
|
|
|
|
// path: ROUTES.BUCKETS.path,
|
|
|
|
// name: ROUTES.BUCKETS.name,
|
|
|
|
// component: BucketArea
|
|
|
|
// },
|
2019-01-09 15:40:21 +00:00
|
|
|
// {
|
|
|
|
// path: '/',
|
|
|
|
// name: 'dashboardArea',
|
|
|
|
// component: DashboardArea
|
|
|
|
// },
|
2019-02-20 13:33:56 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '*',
|
|
|
|
name: '404',
|
|
|
|
component: Page404
|
2019-03-14 12:48:43 +00:00
|
|
|
},
|
2019-02-20 13:33:56 +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
|
2019-04-05 16:08:14 +01:00
|
|
|
// and if we are able to navigate to page without existing project
|
2018-11-28 09:16:35 +00:00
|
|
|
router.beforeEach((to, from, next) => {
|
2019-04-05 16:08:14 +01:00
|
|
|
if (isUnavailablePageWithoutProject(to.name as string)) {
|
2019-06-06 16:40:17 +01:00
|
|
|
next(ROUTES.PROJECT_OVERVIEW.path + '/' + ROUTES.PROJECT_DETAILS.path);
|
2019-04-05 16:08:14 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
if (to.matched.some(route => route.meta.requiresAuth)) {
|
2019-07-22 10:46:26 +01:00
|
|
|
if (!AuthToken.get()) {
|
2019-02-20 13:33:56 +00:00
|
|
|
next(ROUTES.LOGIN);
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 09:16:35 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
next();
|
2018-11-28 09:16:35 +00:00
|
|
|
});
|
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
// isUnavailablePageWithoutProject checks if we are able to navigate to page without existing project
|
|
|
|
function isUnavailablePageWithoutProject(pageName: string): boolean {
|
2019-07-19 14:40:42 +01:00
|
|
|
let unavailablePages: string[] = [ROUTES.TEAM.name, ROUTES.API_KEYS.name, ROUTES.BUCKETS.name];
|
2019-04-05 16:08:14 +01:00
|
|
|
const state = store.state as any;
|
|
|
|
|
|
|
|
let isProjectSelected = state.projectsModule.selectedProject.id !== '';
|
|
|
|
|
|
|
|
return unavailablePages.includes(pageName) && !isProjectSelected;
|
|
|
|
}
|
|
|
|
|
2018-11-28 09:16:35 +00:00
|
|
|
export default router;
|