Add Starter middleware & Restore the Data have changed notification

This commit is contained in:
Bubka
2023-10-25 17:26:32 +02:00
parent 4dbbae24dc
commit 8c23aa884f
6 changed files with 73 additions and 30 deletions

View File

@@ -27,7 +27,8 @@ import EditCredential from '../views/settings/Credentials/Edit.vue'
import Errors from '../views/Error.vue'
import About from '../views/About.vue'
import authGuard from './middlewares/authGuard'
import authGuard from './middlewares/authGuard'
import starter from './middlewares/starter'
import noEmptyError from './middlewares/noEmptyError'
const router = createRouter({
@@ -36,7 +37,7 @@ const router = createRouter({
{ path: '/start', name: 'start', component: Start, meta: { middlewares: [authGuard] } },
{ path: '/capture', name: 'capture', component: Capture, meta: { middlewares: [authGuard] } },
{ path: '/accounts', name: 'accounts', component: Accounts, meta: { middlewares: [authGuard] }, alias: '/' },
{ path: '/accounts', name: 'accounts', component: Accounts, meta: { middlewares: [authGuard, starter] }, alias: '/' },
{ path: '/account/create', name: 'createAccount', component: CreateAccount, meta: { middlewares: [authGuard] } },
{ path: '/account/import', name: 'importAccounts', component: ImportAccount, meta: { middlewares: [authGuard] } },
{ path: '/account/:twofaccountId/edit', name: 'editAccount', component: EditAccount, meta: { middlewares: [authGuard] } },

View File

@@ -0,0 +1,19 @@
import { useTwofaccounts } from '@/stores/twofaccounts'
/**
* Allows the user to access the main view only if he owns at least one twofaccount.
* Push to the starter view otherwise.
*/
export default function starter({ to, next }) {
const twofaccounts = useTwofaccounts()
if (twofaccounts.isEmpty) {
twofaccounts.refresh().then(() => {
if (twofaccounts.isEmpty) {
next({ name: 'start' });
}
else next()
})
}
else next()
}