protegidas rutas
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { defineRouter } from '#q-app/wrappers'
|
import { defineRouter } from '#q-app/wrappers'
|
||||||
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
|
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
|
||||||
import routes from './routes'
|
import routes from './routes'
|
||||||
|
import { supabaseStore } from 'src/stores/supabaseStore'
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If not building with SSR mode, you can
|
* If not building with SSR mode, you can
|
||||||
@@ -27,10 +29,15 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
|||||||
})
|
})
|
||||||
// to hacia
|
// to hacia
|
||||||
// from desde
|
// from desde
|
||||||
|
const store = supabaseStore()
|
||||||
Router.beforeEach((to, from, next) => {
|
Router.beforeEach((to, from, next) => {
|
||||||
//console.log(to)
|
if (to.meta.requiresAuth && !store.user) {
|
||||||
//console.log(from)
|
next('/login')
|
||||||
|
} else if (!to.meta.requiresAuth && store.user) {
|
||||||
|
next('/')
|
||||||
|
} else {
|
||||||
next()
|
next()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return Router
|
return Router
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const routes = [
|
|||||||
path: '/',
|
path: '/',
|
||||||
component: () => import('layouts/MainLayout.vue'),
|
component: () => import('layouts/MainLayout.vue'),
|
||||||
children: [
|
children: [
|
||||||
{ path: '', component: () => import('pages/IndexPage.vue') }
|
{ path: '', component: () => import('pages/IndexPage.vue'), meta: { requiresAuth: true } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user