protegidas rutas

This commit is contained in:
2025-02-06 00:04:23 +01:00
parent 874f893d6d
commit b515a68d02
2 changed files with 11 additions and 4 deletions

View File

@@ -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)
if (to.meta.requiresAuth && !store.user) {
next('/login')
} else if (!to.meta.requiresAuth && store.user) {
next('/')
} else {
next()
}
})
return Router

View File

@@ -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 } }
]
},