diff --git a/src/router/index.js b/src/router/index.js index 11827f5..d172618 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,8 @@ import { defineRouter } from '#q-app/wrappers' import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router' import routes from './routes' +import { supabaseStore } from 'src/stores/supabaseStore' + /* * If not building with SSR mode, you can @@ -27,10 +29,15 @@ export default defineRouter(function (/* { store, ssrContext } */) { }) // to hacia // from desde + const store = supabaseStore() Router.beforeEach((to, from, next) => { - //console.log(to) - //console.log(from) - next() + if (to.meta.requiresAuth && !store.user) { + next('/login') + } else if (!to.meta.requiresAuth && store.user) { + next('/') + } else { + next() + } }) return Router diff --git a/src/router/routes.js b/src/router/routes.js index b4f7d1f..99e5d4b 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -13,7 +13,7 @@ const routes = [ path: '/', component: () => import('layouts/MainLayout.vue'), children: [ - { path: '', component: () => import('pages/IndexPage.vue') } + { path: '', component: () => import('pages/IndexPage.vue'), meta: { requiresAuth: true } } ] },