From 13730eecbc654fe9aa7425dbf377730ef74a3039 Mon Sep 17 00:00:00 2001 From: clonbg Date: Mon, 9 Sep 2024 19:01:33 +0200 Subject: [PATCH] registro completado --- src/router/index.js | 72 +++++++++++---------- src/views/RegistroView.vue | 128 ++++++++++++++++++++++++++++++++++--- 2 files changed, 156 insertions(+), 44 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 08fd1b2..4224568 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,62 +1,66 @@ -import { createRouter, createWebHistory } from 'vue-router' -import { useUserStore } from '@/stores/user' - +import { createRouter, createWebHistory } from "vue-router"; +import { useUserStore } from "@/stores/user"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { - path: '/', - name: 'Login', - component: () => import('../views/LoginView.vue') + path: "/", + name: "Login", + component: () => import("../views/LoginView.vue"), }, { - path: '/registro', - name: 'Registro', - component: () => import('../views/RegistroView.vue') + path: "/registro", + name: "Registro", + component: () => import("../views/RegistroView.vue"), }, { - path: '/listas', - name: 'listas', + path: "/listas", + name: "listas", // route level code-splitting // this generates a separate chunk (About.[hash].js) for this route // which is lazy-loaded when the route is visited. - component: () => import('../views/ListasView.vue'), + component: () => import("../views/ListasView.vue"), meta: { requiresAuth: true }, }, { - path: '/lista/:id', - name: 'lista', - component: () => import('../components/Lista.vue'), - meta: { requiresAuth: true } + path: "/lista/:id", + name: "lista", + component: () => import("../components/Lista.vue"), + meta: { requiresAuth: true }, }, { - path: '/:pathMatch(.*)*', - name: 'NotFound', - component: () => import('../components/404.vue') + path: "/:pathMatch(.*)*", + name: "NotFound", + component: () => import("../components/404.vue"), }, - ] -}) + ], +}); router.beforeEach((to, from) => { // ✅ This will work because the router starts its navigation after // the router is installed and pinia will be installed too - const storeUser = useUserStore() + const storeUser = useUserStore(); if (!from.meta.requiresAuth && to.meta.requiresAuth && !storeUser.isValid) { - //console.log('caso 1', from.name) + console.log("caso 1", from.name); if (from.name) { - //console.log('1a') - return false + console.log("1a"); + return false; } else { - //console.log('1b') - return '/' + console.log("1b"); + return "/"; } } - if (to.fullPath == '/') { - //console.log('caso 2') - storeUser.user = '' - storeUser.isValid = false - } -}) + if (to.fullPath == "/") { + if (from.fullPath!="/registro") { + console.log("caso 2a"); + storeUser.user = ""; + storeUser.isValid = false; + } else { + console.log('caso 2b') + } -export default router + } +}); + +export default router; diff --git a/src/views/RegistroView.vue b/src/views/RegistroView.vue index bd40b9b..961e12a 100644 --- a/src/views/RegistroView.vue +++ b/src/views/RegistroView.vue @@ -1,19 +1,19 @@ \ No newline at end of file +