2023-09-27 10:44:54 +02:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
import middlewarePipeline from "@/router/middlewarePipeline";
|
|
|
|
import { useUserStore } from '@/stores/user'
|
2023-10-27 15:16:07 +02:00
|
|
|
import { useTwofaccounts } from '@/stores/twofaccounts'
|
2023-09-27 10:44:54 +02:00
|
|
|
|
2023-10-30 12:53:41 +01:00
|
|
|
import Start from '../views/Start.vue'
|
|
|
|
import Accounts from '../views/Accounts.vue'
|
|
|
|
import Capture from '../views/twofaccounts/Capture.vue'
|
|
|
|
import CreateUpdateAccount from '../views/twofaccounts/CreateUpdate.vue'
|
|
|
|
import ImportAccount from '../views/twofaccounts/Import.vue'
|
|
|
|
import QRcodeAccount from '../views/twofaccounts/QRcode.vue'
|
|
|
|
import Groups from '../views/groups/Groups.vue'
|
|
|
|
import CreateUpdateGroup from '../views/groups/CreateUpdate.vue'
|
|
|
|
import Login from '../views/auth/Login.vue'
|
|
|
|
import Register from '../views/auth/Register.vue'
|
|
|
|
import PasswordRequest from '../views/auth/password/Request.vue'
|
2023-10-30 15:13:50 +01:00
|
|
|
import PasswordReset from '../views/auth/password/Reset.vue'
|
2023-10-30 12:53:41 +01:00
|
|
|
import WebauthnLost from '../views/auth/webauthn/Lost.vue'
|
|
|
|
// import WebauthnRecover from './views/auth/webauthn/Recover.vue'
|
|
|
|
import SettingsOptions from '../views/settings/Options.vue'
|
|
|
|
import SettingsAccount from '../views/settings/Account.vue'
|
|
|
|
import SettingsOAuth from '../views/settings/OAuth.vue'
|
|
|
|
import SettingsWebAuthn from '../views/settings/WebAuthn.vue'
|
|
|
|
import EditCredential from '../views/settings/Credentials/Edit.vue'
|
|
|
|
import Errors from '../views/Error.vue'
|
|
|
|
import About from '../views/About.vue'
|
2023-09-27 10:44:54 +02:00
|
|
|
|
2023-10-25 17:26:32 +02:00
|
|
|
import authGuard from './middlewares/authGuard'
|
|
|
|
import starter from './middlewares/starter'
|
2023-09-28 11:27:45 +02:00
|
|
|
import noEmptyError from './middlewares/noEmptyError'
|
2023-09-27 10:44:54 +02:00
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHistory('/'),
|
|
|
|
routes: [
|
2023-10-09 13:00:56 +02:00
|
|
|
{ path: '/start', name: 'start', component: Start, meta: { middlewares: [authGuard] } },
|
|
|
|
{ path: '/capture', name: 'capture', component: Capture, meta: { middlewares: [authGuard] } },
|
2023-09-27 10:44:54 +02:00
|
|
|
|
2023-10-25 17:26:32 +02:00
|
|
|
{ path: '/accounts', name: 'accounts', component: Accounts, meta: { middlewares: [authGuard, starter] }, alias: '/' },
|
2023-10-30 12:53:41 +01:00
|
|
|
{ path: '/account/create', name: 'createAccount', component: CreateUpdateAccount, meta: { middlewares: [authGuard] } },
|
2023-10-09 13:00:56 +02:00
|
|
|
{ path: '/account/import', name: 'importAccounts', component: ImportAccount, meta: { middlewares: [authGuard] } },
|
2023-10-30 12:53:41 +01:00
|
|
|
{ path: '/account/:twofaccountId/edit', name: 'editAccount', component: CreateUpdateAccount, meta: { middlewares: [authGuard] }, props: true },
|
2023-10-20 13:28:17 +02:00
|
|
|
{ path: '/account/:twofaccountId/qrcode', name: 'showQRcode', component: QRcodeAccount, meta: { middlewares: [authGuard] } },
|
2023-09-27 10:44:54 +02:00
|
|
|
|
2023-10-20 13:28:17 +02:00
|
|
|
{ path: '/groups', name: 'groups', component: Groups, meta: { middlewares: [authGuard] }, props: true },
|
2023-10-27 15:27:15 +02:00
|
|
|
{ path: '/group/create', name: 'createGroup', component: CreateUpdateGroup, meta: { middlewares: [authGuard] } },
|
|
|
|
{ path: '/group/:groupId/edit', name: 'editGroup', component: CreateUpdateGroup, meta: { middlewares: [authGuard] }, props: true },
|
2023-09-27 10:44:54 +02:00
|
|
|
|
2023-10-04 09:30:05 +02:00
|
|
|
{ path: '/settings/options', name: 'settings.options', component: SettingsOptions, meta: { middlewares: [authGuard], showAbout: true } },
|
2023-10-05 17:04:51 +02:00
|
|
|
{ path: '/settings/account', name: 'settings.account', component: SettingsAccount, meta: { middlewares: [authGuard], showAbout: true } },
|
2023-10-06 10:45:10 +02:00
|
|
|
{ path: '/settings/oauth', name: 'settings.oauth.tokens', component: SettingsOAuth, meta: { middlewares: [authGuard], showAbout: true, props: true } },
|
2023-10-05 14:09:04 +02:00
|
|
|
{ path: '/settings/webauthn/:credentialId/edit', name: 'settings.webauthn.editCredential', component: EditCredential, meta: { middlewares: [authGuard], showAbout: true }, props: true },
|
|
|
|
{ path: '/settings/webauthn', name: 'settings.webauthn.devices', component: SettingsWebAuthn, meta: { middlewares: [authGuard], showAbout: true } },
|
2023-09-27 10:44:54 +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: '/password/request', name: 'password.request', component: PasswordRequest, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
2023-10-30 15:13:50 +01:00
|
|
|
{ path: '/user/password/reset', name: 'password.reset', component: PasswordReset, meta: { disabledWithAuthProxy: true, showAbout: true } },
|
2023-09-27 10:44:54 +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 } },
|
|
|
|
|
2023-09-28 11:27:45 +02:00
|
|
|
{ path: '/about', name: 'about', component: About, meta: { showAbout: true } },
|
|
|
|
{ path: '/error', name: 'genericError', component: Errors, meta: { middlewares: [noEmptyError], err: null } },
|
2023-09-27 10:44:54 +02:00
|
|
|
// { path: '/404', name: '404',component: Errors, props: true },
|
|
|
|
// { path: '*', redirect: { name: '404' } },
|
|
|
|
|
|
|
|
// Lazy loaded view
|
|
|
|
{ path: '/about', name: 'about', component: () => import('../views/About.vue') }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
const middlewares = to.meta.middlewares
|
|
|
|
const user = useUserStore()
|
2023-10-27 15:16:07 +02:00
|
|
|
const twofaccounts = useTwofaccounts()
|
|
|
|
const stores = { user: user, twofaccounts: twofaccounts }
|
2023-09-27 10:44:54 +02:00
|
|
|
const context = { to, from, next, stores }
|
|
|
|
|
|
|
|
if (!middlewares) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
middlewares[0]({
|
|
|
|
...context,
|
|
|
|
next: middlewarePipeline(context, middlewares, 1),
|
|
|
|
});
|
2023-09-29 13:11:02 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
router.afterEach((to, from) => {
|
|
|
|
to.meta.title = trans('titles.' + to.name)
|
|
|
|
document.title = to.meta.title
|
|
|
|
})
|
2023-09-27 10:44:54 +02:00
|
|
|
|
|
|
|
export default router
|