From efbe1d2d69488a6b78e627a27ad12faf4ab025f5 Mon Sep 17 00:00:00 2001 From: Clonbg Date: Wed, 4 Sep 2024 13:48:20 +0200 Subject: [PATCH] no change url with buttons back and forward --- src/router/index.js | 14 +++++++++++--- src/stores/user.js | 2 +- src/views/LoginView.vue | 3 --- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index b1b798a..6a647ce 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -38,12 +38,20 @@ const router = createRouter({ ] }) -router.beforeEach((to) => { +router.beforeEach((to, from) => { // ✅ This will work because the router starts its navigation after // the router is installed and pinia will be installed too const storeUser = useUserStore() - console.log(storeUser.isValid) - if (to.meta.requiresAuth && !storeUser.isValid) return '/' + if (to.meta.requiresAuth && !storeUser.isValid) { + if (from.fullPath == '/') { + return false + } + return '/' + } + if (to.fullPath == '/') { + storeUser.user = '' + storeUser.isValid = false + } }) export default router diff --git a/src/stores/user.js b/src/stores/user.js index 95f99fb..e5e1d7b 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -3,7 +3,7 @@ import { defineStore } from 'pinia' export const useUserStore = defineStore('user', () => { const user = ref() - const isValid = ref() + const isValid = ref(false) return { user, isValid } }) \ No newline at end of file diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index e490da5..f56b5c9 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -142,9 +142,6 @@ const visibleModalSended = ref(false); const visibleModalInvalid = ref(false); onMounted(() => { - if (pb != null) { - pb.authStore.clear(); - } pb = new PocketBase("http://127.0.0.1:8090"); });