From 157b36269f042bf7fe3928ed3e5af13ac09ae4ac Mon Sep 17 00:00:00 2001 From: Elliot Axel Noriega Date: Fri, 30 Aug 2024 13:19:34 -0600 Subject: [PATCH] Resolucion de redireccion de envio de verificacion de cuenta y reset password --- cosiap_frontend/src/App.jsx | 8 ++++---- .../src/components/common/utility/Autenticador.jsx | 4 ++++ .../src/components/common/utility/LoginRequiredRoute.jsx | 6 ++++-- cosiap_frontend/src/components/users/Login/LoginForm.jsx | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cosiap_frontend/src/App.jsx b/cosiap_frontend/src/App.jsx index 9c0fc17..ce49036 100644 --- a/cosiap_frontend/src/App.jsx +++ b/cosiap_frontend/src/App.jsx @@ -47,11 +47,11 @@ function App() { } function RoutesApp( {setViewPageLoader} ){ - const {token} = useAutenticacion(); - + const {token, isAdmin} = useAutenticacion(); + console.log(token) return ( - } /> + } /> {/* Rutas públicas */} {/* Componente del layout */} }> @@ -74,7 +74,7 @@ function RoutesApp( {setViewPageLoader} ){ } /> } /> } /> - } /> + } /> {/* Solo administradores pueden acceder a estas url */} }> } /> diff --git a/cosiap_frontend/src/components/common/utility/Autenticador.jsx b/cosiap_frontend/src/components/common/utility/Autenticador.jsx index 22f83e3..9dbe2a8 100644 --- a/cosiap_frontend/src/components/common/utility/Autenticador.jsx +++ b/cosiap_frontend/src/components/common/utility/Autenticador.jsx @@ -8,6 +8,7 @@ import { } from "react"; import api from '@/api' import PropTypes from 'prop-types'; +import { useNavigate } from "react-router-dom"; const ContextoAut = createContext(undefined); @@ -27,6 +28,7 @@ export const Autenticador = ({ setViewPageLoader, children }) => { const [isAdmin, setIsAdmin] = useState(); const [uid, setUid] = useState(); const interceptadoresRef = useRef({}); + const navigate = useNavigate(); useEffect(() => { const buscarUsuario = async () => { @@ -43,6 +45,7 @@ export const Autenticador = ({ setViewPageLoader, children }) => { } catch { setToken(null); setIsAdmin(false); + setUid(undefined); } } @@ -114,6 +117,7 @@ export const Autenticador = ({ setViewPageLoader, children }) => { setToken(null); setIsAdmin(undefined); setUid(undefined); + navigate('/authentication'); } catch (error) { console.error('Logout unsuccessful', error); } diff --git a/cosiap_frontend/src/components/common/utility/LoginRequiredRoute.jsx b/cosiap_frontend/src/components/common/utility/LoginRequiredRoute.jsx index 3ff2a8d..b82f3dc 100644 --- a/cosiap_frontend/src/components/common/utility/LoginRequiredRoute.jsx +++ b/cosiap_frontend/src/components/common/utility/LoginRequiredRoute.jsx @@ -1,10 +1,12 @@ import { useAutenticacion } from "@/components/common/utility/Autenticador"; import { useState, useEffect } from "react"; -import { Navigate, Outlet } from "react-router-dom"; +import { Navigate, Outlet, useLocation } from "react-router-dom"; import api from "@/api"; export const LoginRequiredRoute = () => { + const location = useLocation(); const { token } = useAutenticacion(); + console.log(location) if (token === null) { return ; } else if (token === undefined) { @@ -31,6 +33,6 @@ export const IsLogged = () => { if (token === null) { return }else{ - return ; + return null; } }; diff --git a/cosiap_frontend/src/components/users/Login/LoginForm.jsx b/cosiap_frontend/src/components/users/Login/LoginForm.jsx index 7383d8a..d2efa3d 100644 --- a/cosiap_frontend/src/components/users/Login/LoginForm.jsx +++ b/cosiap_frontend/src/components/users/Login/LoginForm.jsx @@ -9,12 +9,11 @@ import { LoginInputPassword } from "@/components/users/Login/LoginInputPassword" import { useState } from "react"; import {ErrorDisplay} from '@/components/common/ui/ErrorDisplay' import {useAutenticacion} from "@/components/common/utility/Autenticador" - - +import { useNavigate } from "react-router-dom"; export function LoginForm( {setViewPageLoader} ) { const [loginError, setLoginError] = useState(''); - + const navigate = useNavigate() const { setToken, setIsAdmin, configurarInterceptors, setUid } = useAutenticacion(); const { register, @@ -38,6 +37,7 @@ export function LoginForm( {setViewPageLoader} ) { //Extraemos el id const responseUid = await api.usuarios.getId(); setUid(responseUid.data.user_id); + navigate('/inicio'); } catch (error) { console.error("Login failed:", error); setLoginError(error.response.data.detail) -- GitLab