no change url with buttons back and forward

This commit is contained in:
2024-09-04 13:48:20 +02:00
parent 86ee49bf80
commit efbe1d2d69
3 changed files with 12 additions and 7 deletions

View File

@@ -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

View File

@@ -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 }
})

View File

@@ -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");
});