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 About from '@/views/documentation/About.vue'
import ContentPolicy from '@/views/documentation/ContentPolicy.vue'
@@ -26,7 +27,7 @@ const routes = [
{
path: '/',
component: Home,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/browse',
@@ -65,53 +66,53 @@ const routes = [
path: '/@mathieucaron',
component: MathieuCaron
},
{
path: '/helpandcontact',
component: HelpAndContact,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/termsandconditions',
name: 'termsandconditions',
component: TermsAndConditions,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/contentpolicy',
name: 'contentpolicy',
component: ContentPolicy,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/faq',
name: 'FAQ',
component: FAQ,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/guideforcreators',
name: 'guideforcreators',
component: CreatorGuide,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/about',
name: 'about',
component: About,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/pricing',
name: 'pricing',
component: Pricing,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
path: '/join',
name: 'join',
component: Join,
meta: {hideSideBar: true}
meta: { hideSideBar: true }
},
{
@@ -122,7 +123,8 @@ const routes = [
{
path: '/profile',
name: 'profile',
component: Profile
component: Profile,
meta: { requiresAuth: true }
},
{
path: '/signup',
@@ -137,7 +139,8 @@ const routes = [
{
path: '/wallet',
name: 'wallet',
component: Wallet
component: Wallet,
meta: { requiresAuth: true }
}
]
@@ -146,4 +149,20 @@ const router = createRouter({
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;