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'
@@ -26,7 +27,7 @@ const routes = [
{ {
path: '/', path: '/',
component: Home, component: Home,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/browse', path: '/browse',
@@ -69,49 +70,49 @@ const routes = [
{ {
path: '/helpandcontact', path: '/helpandcontact',
component: HelpAndContact, component: HelpAndContact,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/termsandconditions', path: '/termsandconditions',
name: 'termsandconditions', name: 'termsandconditions',
component: TermsAndConditions, component: TermsAndConditions,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/contentpolicy', path: '/contentpolicy',
name: 'contentpolicy', name: 'contentpolicy',
component: ContentPolicy, component: ContentPolicy,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/faq', path: '/faq',
name: 'FAQ', name: 'FAQ',
component: FAQ, component: FAQ,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/guideforcreators', path: '/guideforcreators',
name: 'guideforcreators', name: 'guideforcreators',
component: CreatorGuide, component: CreatorGuide,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/about', path: '/about',
name: 'about', name: 'about',
component: About, component: About,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/pricing', path: '/pricing',
name: 'pricing', name: 'pricing',
component: Pricing, component: Pricing,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
path: '/join', path: '/join',
name: 'join', name: 'join',
component: Join, component: Join,
meta: {hideSideBar: true} meta: { hideSideBar: true }
}, },
{ {
@@ -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;