From 40ea7677997c42d17526881055396a44bd896515 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:16:07 +0200 Subject: [PATCH] Add the twofaccounts store to stores passed to the router middlewares --- resources/js_vue3/router/index.js | 4 +++- resources/js_vue3/router/middlewares/starter.js | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/js_vue3/router/index.js b/resources/js_vue3/router/index.js index d4eab4e3..ce62e635 100644 --- a/resources/js_vue3/router/index.js +++ b/resources/js_vue3/router/index.js @@ -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) { diff --git a/resources/js_vue3/router/middlewares/starter.js b/resources/js_vue3/router/middlewares/starter.js index aca46db6..8561c925 100644 --- a/resources/js_vue3/router/middlewares/starter.js +++ b/resources/js_vue3/router/middlewares/starter.js @@ -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(() => {