misc_pterodactyl-panel/resources/assets/scripts/router.ts

81 lines
3.1 KiB
TypeScript
Raw Normal View History

2018-12-16 23:29:44 +00:00
import VueRouter, {Route} from 'vue-router';
import store from './store/index';
2019-02-10 05:14:58 +00:00
import User from './models/user';
// Base Vuejs Templates
2019-02-10 05:14:58 +00:00
import Login from './components/auth/Login.vue';
import Dashboard from './components/dashboard/Dashboard.vue';
import Account from './components/dashboard/Account.vue';
import ResetPassword from './components/auth/ResetPassword.vue';
import LoginForm from "@/components/auth/LoginForm.vue";
import ForgotPassword from "@/components/auth/ForgotPassword.vue";
import TwoFactorForm from "@/components/auth/TwoFactorForm.vue";
import Server from "@/components/server/Server.vue";
import ConsolePage from "@/components/server/subpages/Console.vue";
import FileManagerPage from "@/components/server/subpages/FileManager.vue";
import DatabasesPage from "@/components/server/subpages/Databases.vue";
2019-02-10 05:15:45 +00:00
const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default;
const routes = [
2019-02-10 05:14:58 +00:00
{
path: '/auth', component: Login,
children: [
2019-02-10 05:15:45 +00:00
{name: 'login', path: 'login', component: LoginForm},
{name: 'forgot-password', path: 'password', component: ForgotPassword},
{name: 'checkpoint', path: 'checkpoint', component: TwoFactorForm},
2019-02-10 05:14:58 +00:00
]
},
{
name: 'reset-password',
path: '/auth/password/reset/:token',
component: ResetPassword,
2018-12-16 23:29:44 +00:00
props: function (route: Route) {
return {token: route.params.token, email: route.query.email || ''};
2018-12-16 23:29:44 +00:00
},
},
{name: 'dashboard', path: '/', component: Dashboard},
{name: 'account', path: '/account', component: Account},
{name: 'account.api', path: '/account/api', component: Account},
{name: 'account.security', path: '/account/security', component: Account},
2018-12-16 23:29:44 +00:00
{
path: '/server/:id', component: Server,
2018-07-16 02:03:38 +00:00
children: [
2018-12-16 23:29:44 +00:00
{name: 'server', path: '', component: ConsolePage},
{name: 'server-files', path: 'files/:path(.*)?', component: FileManagerPage},
2019-02-03 23:39:59 +00:00
// {name: 'server-subusers', path: 'subusers', component: ServerSubusers},
// {name: 'server-schedules', path: 'schedules', component: ServerSchedules},
2018-12-16 23:29:44 +00:00
{name: 'server-databases', path: 'databases', component: DatabasesPage},
2019-02-03 23:39:59 +00:00
// {name: 'server-allocations', path: 'allocations', component: ServerAllocations},
// {name: 'server-settings', path: 'settings', component: ServerSettings},
2018-12-16 23:29:44 +00:00
],
},
];
const router = new VueRouter({
2018-12-16 23:29:44 +00:00
mode: 'history', routes,
});
// Redirect the user to the login page if they try to access a protected route and
// have no JWT or the JWT is expired and wouldn't be accepted by the Panel.
router.beforeEach((to, from, next) => {
if (to.path === route('auth.logout')) {
return window.location = route('auth.logout');
}
const user = store.getters['auth/getUser'];
// Check that if we're accessing a non-auth route that a user exists on the page.
if (!to.path.startsWith('/auth') && !(user instanceof User)) {
store.commit('auth/logout');
return window.location = route('auth.logout');
}
// Continue on through the pipeline.
return next();
});
export default router;