Add the twofaccounts store to stores passed to the router middlewares

This commit is contained in:
Bubka 2023-10-27 15:16:07 +02:00
parent 79827663fe
commit 40ea767799
2 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import middlewarePipeline from "@/router/middlewarePipeline";
import { useUserStore } from '@/stores/user'
import { useTwofaccounts } from '@/stores/twofaccounts'
import Start from '../views/Start.vue'
import Accounts from '../views/Accounts.vue'
@ -74,7 +75,8 @@ const router = createRouter({
router.beforeEach((to, from, next) => {
const middlewares = to.meta.middlewares
const user = useUserStore()
const stores = { user: user }
const twofaccounts = useTwofaccounts()
const stores = { user: user, twofaccounts: twofaccounts }
const context = { to, from, next, stores }
if (!middlewares) {

View File

@ -1,11 +1,9 @@
import { useTwofaccounts } from '@/stores/twofaccounts'
/**
* Allows the user to access the main view only if he owns at least one twofaccount.
* Allows an authenticated 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()
export default function starter({ to, next, stores }) {
const { twofaccounts } = stores
if (twofaccounts.isEmpty) {
twofaccounts.refresh().then(() => {