I added a redirect when we are on the wallet and profile pages and we are not logged in.

This commit is contained in:
PascalMarchesseault
2024-07-08 00:06:03 -04:00
parent 52c5a0ef55
commit 7d8d0b4d2b

View File

@@ -1,4 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from "@/stores/user.js";
import GuillaumeAime from '@/views/manualusers/GuillaumeAime.vue' import GuillaumeAime from '@/views/manualusers/GuillaumeAime.vue'
import About from '@/views/documentation/About.vue' import About from '@/views/documentation/About.vue'
import ContentPolicy from '@/views/documentation/ContentPolicy.vue' import ContentPolicy from '@/views/documentation/ContentPolicy.vue'
@@ -122,7 +123,8 @@ const routes = [
{ {
path: '/profile', path: '/profile',
name: 'profile', name: 'profile',
component: Profile component: Profile,
meta: { requiresAuth: true }
}, },
{ {
path: '/signup', path: '/signup',
@@ -137,7 +139,8 @@ const routes = [
{ {
path: '/wallet', path: '/wallet',
name: 'wallet', name: 'wallet',
component: Wallet component: Wallet,
meta: { requiresAuth: true }
} }
] ]
@@ -146,4 +149,20 @@ const router = createRouter({
routes routes
}) })
export default router // Navigation gards
router.beforeEach((to, from, next) => {
const authStore = useUserStore();
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!authStore.user.value || !Object.keys(authStore.user.value).length) {
next('/');
} else {
next();
}
} else {
next();
}
})
export default router;