2020-01-16 13:50:53 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Router from 'vue-router'
|
|
|
|
|
|
|
|
Vue.use(Router)
|
|
|
|
|
2020-11-20 14:11:32 +01:00
|
|
|
import Start from './views/Start'
|
2020-11-23 19:30:58 +01:00
|
|
|
import Capture from './views/Capture'
|
2020-01-18 18:19:37 +01:00
|
|
|
import Accounts from './views/Accounts'
|
2020-10-22 17:15:05 +02:00
|
|
|
import CreateAccount from './views/twofaccounts/Create'
|
|
|
|
import EditAccount from './views/twofaccounts/Edit'
|
2020-11-20 14:11:32 +01:00
|
|
|
import QRcodeAccount from './views/twofaccounts/QRcode'
|
2020-10-22 17:15:05 +02:00
|
|
|
import Groups from './views/Groups'
|
|
|
|
import CreateGroup from './views/groups/Create'
|
|
|
|
import EditGroup from './views/groups/Edit'
|
2020-01-18 18:19:37 +01:00
|
|
|
import Login from './views/auth/Login'
|
|
|
|
import Register from './views/auth/Register'
|
|
|
|
import PasswordRequest from './views/auth/password/Request'
|
|
|
|
import PasswordReset from './views/auth/password/Reset'
|
2020-09-25 23:36:11 +02:00
|
|
|
import Settings from './views/settings/Index'
|
2020-01-27 21:41:47 +01:00
|
|
|
import Errors from './views/Error'
|
2020-01-16 13:50:53 +01:00
|
|
|
|
|
|
|
const router = new Router({
|
|
|
|
mode: 'history',
|
|
|
|
routes: [
|
2020-11-20 14:11:32 +01:00
|
|
|
{ path: '/start', name: 'start', component: Start, meta: { requiresAuth: true }, props: true },
|
2020-11-23 19:30:58 +01:00
|
|
|
{ path: '/capture', name: 'capture', component: Capture, meta: { requiresAuth: true }, props: true },
|
2020-11-20 14:11:32 +01:00
|
|
|
|
2020-10-06 20:34:00 +02:00
|
|
|
{ path: '/accounts', name: 'accounts', component: Accounts, meta: { requiresAuth: true }, alias: '/', props: true },
|
2020-10-22 17:15:05 +02:00
|
|
|
{ path: '/account/create', name: 'createAccount', component: CreateAccount, meta: { requiresAuth: true } },
|
|
|
|
{ path: '/account/edit/:twofaccountId', name: 'editAccount', component: EditAccount, meta: { requiresAuth: true } },
|
2020-11-02 13:39:43 +01:00
|
|
|
{ path: '/account/qrcode/:twofaccountId', name: 'showQRcode', component: QRcodeAccount, meta: { requiresAuth: true } },
|
2020-10-22 17:15:05 +02:00
|
|
|
|
|
|
|
{ path: '/groups', name: 'groups', component: Groups, meta: { requiresAuth: true }, props: true },
|
|
|
|
{ path: '/group/create', name: 'createGroup', component: CreateGroup, meta: { requiresAuth: true } },
|
|
|
|
{ path: '/group/edit/:groupId', name: 'editGroup', component: EditGroup, meta: { requiresAuth: true } },
|
|
|
|
|
2020-10-06 20:34:00 +02:00
|
|
|
{ path: '/settings', name: 'settings', component: Settings, meta: { requiresAuth: true } },
|
2020-01-16 13:50:53 +01:00
|
|
|
|
2020-10-06 20:34:00 +02:00
|
|
|
{ path: '/login', name: 'login', component: Login },
|
|
|
|
{ path: '/register', name: 'register', component: Register },
|
2020-01-16 13:50:53 +01:00
|
|
|
{ path: '/password/request', name: 'password.request', component: PasswordRequest },
|
|
|
|
{ path: '/password/reset/:token', name: 'password.reset', component: PasswordReset },
|
|
|
|
|
2020-01-27 21:41:47 +01:00
|
|
|
{ path: '/flooded', name: 'flooded',component: Errors,props: true },
|
|
|
|
{ path: '/error', name: 'genericError',component: Errors,props: true },
|
|
|
|
{ path: '/404', name: '404',component: Errors,props: true },
|
2020-01-16 13:50:53 +01:00
|
|
|
{ path: '*', redirect: { name: '404' } }
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2020-10-06 20:34:00 +02:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.matched.some(record => record.meta.requiresAuth)) {
|
|
|
|
// Accesses to restricted pages without a jwt token are routed to the login page
|
|
|
|
if ( !localStorage.getItem('jwt') ) {
|
|
|
|
next({
|
|
|
|
name: 'login'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// If the jwt token is invalid, a 401 unauthorized is send by the php backend
|
|
|
|
else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-16 13:50:53 +01:00
|
|
|
export default router
|