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'
|
2022-05-25 13:42:43 +02:00
|
|
|
import ImportAccount from './views/twofaccounts/Import'
|
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'
|
2022-07-13 14:56:25 +02:00
|
|
|
import Autolock from './views/auth/Autolock'
|
2020-01-18 18:19:37 +01:00
|
|
|
import PasswordRequest from './views/auth/password/Request'
|
|
|
|
import PasswordReset from './views/auth/password/Reset'
|
2022-03-15 14:47:07 +01:00
|
|
|
import WebauthnLost from './views/auth/webauthn/Lost'
|
2022-03-19 00:14:20 +01:00
|
|
|
import WebauthnRecover from './views/auth/webauthn/Recover'
|
2021-10-29 17:12:58 +02:00
|
|
|
import SettingsOptions from './views/settings/Options'
|
|
|
|
import SettingsAccount from './views/settings/Account'
|
|
|
|
import SettingsOAuth from './views/settings/OAuth'
|
2022-03-15 14:47:07 +01:00
|
|
|
import SettingsWebAuthn from './views/settings/WebAuthn'
|
|
|
|
import EditCredential from './views/settings/Credentials/Edit'
|
2021-10-29 17:12:58 +02:00
|
|
|
import GeneratePAT from './views/settings/PATokens/Create'
|
2020-01-27 21:41:47 +01:00
|
|
|
import Errors from './views/Error'
|
2022-07-21 15:48:23 +02:00
|
|
|
import About from './views/About'
|
2020-01-16 13:50:53 +01:00
|
|
|
|
|
|
|
const router = new Router({
|
|
|
|
mode: 'history',
|
2023-01-20 17:36:15 +01:00
|
|
|
base: window.appConfig.subdirectory ? window.appConfig.subdirectory : '/',
|
2020-01-16 13:50:53 +01:00
|
|
|
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 } },
|
2022-05-25 13:42:43 +02:00
|
|
|
{ path: '/account/import', name: 'importAccounts', component: ImportAccount, meta: { requiresAuth: true } },
|
2021-10-09 19:23:24 +02:00
|
|
|
{ path: '/account/:twofaccountId/edit', name: 'editAccount', component: EditAccount, meta: { requiresAuth: true } },
|
|
|
|
{ path: '/account/:twofaccountId/qrcode', 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 } },
|
2021-10-09 19:23:24 +02:00
|
|
|
{ path: '/group/:groupId/edit', name: 'editGroup', component: EditGroup, meta: { requiresAuth: true }, props: true },
|
2020-10-22 17:15:05 +02:00
|
|
|
|
2022-07-21 15:46:55 +02:00
|
|
|
{ path: '/settings/options', name: 'settings.options', component: SettingsOptions, meta: { requiresAuth: true, showAbout: true } },
|
|
|
|
{ path: '/settings/account', name: 'settings.account', component: SettingsAccount, meta: { requiresAuth: true, showAbout: true } },
|
|
|
|
{ path: '/settings/oauth', name: 'settings.oauth.tokens', component: SettingsOAuth, meta: { requiresAuth: true, showAbout: true } },
|
|
|
|
{ path: '/settings/oauth/pat/create', name: 'settings.oauth.generatePAT', component: GeneratePAT, meta: { requiresAuth: true, showAbout: true } },
|
|
|
|
{ path: '/settings/webauthn/:credentialId/edit', name: 'settings.webauthn.editCredential', component: EditCredential, meta: { requiresAuth: true, showAbout: true }, props: true },
|
|
|
|
{ path: '/settings/webauthn', name: 'settings.webauthn.devices', component: SettingsWebAuthn, meta: { requiresAuth: true, showAbout: true } },
|
2020-01-16 13:50:53 +01:00
|
|
|
|
2022-07-21 15:46:55 +02:00
|
|
|
{ path: '/login', name: 'login', component: Login, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
|
|
|
{ path: '/register', name: 'register', component: Register, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
|
|
|
{ path: '/autolock', name: 'autolock',component: Autolock, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
|
|
|
{ path: '/password/request', name: 'password.request', component: PasswordRequest, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
2022-08-10 19:58:51 +02:00
|
|
|
{ path: '/user/password/reset', name: 'password.reset', component: PasswordReset, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
2022-07-21 15:46:55 +02:00
|
|
|
{ path: '/webauthn/lost', name: 'webauthn.lost', component: WebauthnLost, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
|
|
|
{ path: '/webauthn/recover', name: 'webauthn.recover', component: WebauthnRecover, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
2022-07-13 14:56:25 +02:00
|
|
|
|
2022-07-21 15:48:23 +02:00
|
|
|
{ path: '/about', name: 'about',component: About, meta: { showAbout: true } },
|
2022-07-13 14:56:25 +02:00
|
|
|
{ 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-11-26 20:41:02 +01:00
|
|
|
let isFirstLoad = true;
|
|
|
|
|
2022-05-19 15:50:06 +02:00
|
|
|
router.beforeEach((to, from, next) => {
|
2022-07-07 18:04:04 +02:00
|
|
|
|
2023-09-17 21:44:33 +02:00
|
|
|
document.title = router.app.$options.i18n.t('titles.' + to.name)
|
2022-07-07 18:04:04 +02:00
|
|
|
|
2020-11-26 20:41:02 +01:00
|
|
|
if( to.name === 'accounts') {
|
|
|
|
to.params.isFirstLoad = isFirstLoad ? true : false
|
|
|
|
isFirstLoad = false;
|
|
|
|
}
|
|
|
|
|
2023-08-04 15:13:30 +02:00
|
|
|
// See https://github.com/garethredfern/laravel-vue/ if one day the middleware pattern
|
|
|
|
// becomes relevant (i.e when some admin only pages are necessary)
|
|
|
|
|
|
|
|
if (to.name !== 'login' && to.meta.requiresAuth && ! Vue.$storage.get('authenticated', false)) {
|
|
|
|
next({ name: 'login' })
|
|
|
|
}
|
2023-08-30 14:33:43 +02:00
|
|
|
else if (to.name.startsWith('settings.')) {
|
|
|
|
if (to.params.returnTo == undefined) {
|
|
|
|
if (from.params.returnTo) {
|
2023-09-14 13:39:48 +02:00
|
|
|
next({name: to.name, params: { ...to.params, returnTo: from.params.returnTo }})
|
2023-08-30 14:33:43 +02:00
|
|
|
}
|
|
|
|
else if (from.name) {
|
2023-09-14 13:39:48 +02:00
|
|
|
next({name: to.name, params: { ...to.params, returnTo: from.path }})
|
2023-08-30 14:33:43 +02:00
|
|
|
}
|
|
|
|
else {
|
2023-09-14 13:39:48 +02:00
|
|
|
next({name: to.name, params: { ...to.params, returnTo: '/accounts' }})
|
2023-08-30 14:33:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}
|
2023-08-30 15:34:28 +02:00
|
|
|
else if (to.name == 'about' && to.params.goBackTo == undefined) {
|
|
|
|
if (from.name) {
|
|
|
|
next({ name: to.name, params: {goBackTo: from.path} })
|
|
|
|
}
|
|
|
|
else next({ name: to.name, params: {goBackTo: '/accounts'} })
|
|
|
|
}
|
2023-08-04 15:13:30 +02:00
|
|
|
else if (to.matched.some(record => record.meta.disabledWithAuthProxy)) {
|
2022-05-19 15:50:06 +02:00
|
|
|
if (window.appConfig.proxyAuth) {
|
|
|
|
next({ name: 'accounts' })
|
|
|
|
}
|
|
|
|
else next()
|
|
|
|
}
|
2023-08-04 10:00:59 +02:00
|
|
|
else if (to.name === 'genericError' && to.params.err == undefined) {
|
|
|
|
// return to home if no err object is provided to prevent an empty error message
|
|
|
|
next({ name: 'accounts' });
|
|
|
|
}
|
2022-05-19 15:50:06 +02:00
|
|
|
else next()
|
2020-11-26 20:41:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
router.afterEach(to => {
|
|
|
|
Vue.$storage.set('lastRoute', to.name)
|
2020-10-06 20:34:00 +02:00
|
|
|
});
|
|
|
|
|
2020-01-16 13:50:53 +01:00
|
|
|
export default router
|