I added a redirect when we are on the wallet and profile pages and we are not logged in.
This commit is contained in:
@@ -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',
|
||||
@@ -69,49 +70,49 @@ const routes = [
|
||||
{
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user