protegidas rutas
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 } }
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user