|
@@ -1,5 +1,5 @@
|
1
|
1
|
import React, {useEffect} from 'react'
|
2
|
|
-import { Routes, Route, Navigate, useNavigate } from "react-router-dom";
|
|
2
|
+import { Routes, Route, Navigate, useNavigate, useLocation } from "react-router-dom";
|
3
|
3
|
|
4
|
4
|
import { Dashboard } from "./Dashboard";
|
5
|
5
|
import { Login } from '../Pages/Login'
|
|
@@ -18,45 +18,62 @@ import { Profile } from '../Pages/Profile'
|
18
|
18
|
|
19
|
19
|
import useAuth from '../Auth/useAuth'
|
20
|
20
|
|
|
21
|
+export function RequireAuth({ children }) {
|
|
22
|
+ let auth = useAuth();
|
|
23
|
+ let location = useLocation();
|
|
24
|
+
|
|
25
|
+ console.log('requier auth >> ', auth)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+ if (!auth.isLogged()) {
|
|
29
|
+ // Redirect them to the /login page, but save the current location they were
|
|
30
|
+ // trying to go to when they were redirected. This allows us to send them
|
|
31
|
+ // along to that page after they login, which is a nicer user experience
|
|
32
|
+ // than dropping them off on the home page.
|
|
33
|
+ return <Navigate to="/login" state={{ from: location }} replace />;
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ return children;
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+
|
21
|
40
|
export default function MyRoutes () {
|
22
|
41
|
|
23
|
42
|
let auth = useAuth();
|
24
|
43
|
let navigate = useNavigate()
|
25
|
44
|
|
26
|
45
|
useEffect(() => {
|
27
|
|
- if(!auth.isLogged(0)){
|
28
|
|
- return navigate('/')
|
|
46
|
+ console.log('usse fec check user')
|
|
47
|
+ if(!auth.isLogged()){
|
|
48
|
+ return navigate('login')
|
|
49
|
+ }else{
|
|
50
|
+ return navigate('dashboard/home')
|
29
|
51
|
}
|
30
|
52
|
},[auth,navigate])
|
31
|
|
-
|
32
|
53
|
|
33
|
54
|
return(
|
34
|
55
|
<Routes>
|
35
|
|
-
|
36
|
|
- <Route path="/" element={auth.isLogged() ? <Navigate to='dashboard/home'/> : <Login/>}/>
|
37
|
|
-
|
38
|
|
- {
|
39
|
|
- auth.isLogged() ?
|
40
|
|
- (
|
41
|
|
- <Route path="dashboard" element={<Dashboard/>}>
|
42
|
|
- <Route path="home" element={<Home/>} />
|
43
|
|
- <Route path="puestos" element={<Puestos/>} />
|
44
|
|
- <Route path="perfil" element={<Profile/>} />
|
45
|
|
- <Route path="contrasenas" element={<Contras/>} />
|
46
|
|
- <Route path="expedientes" element={<Expedientes/>} />
|
47
|
|
- <Route path="resultados" element={<Resultados/>} />
|
48
|
|
- <Route path="configuraciones" element={<Configuracion/>} />
|
49
|
|
- <Route path="historial" element={<Historial/>} />
|
50
|
|
- <Route path="pruebas/listar" element={<Pruebas/>} />
|
51
|
|
- <Route path="pruebas/crear" element={<PruebaNueva/>} />
|
52
|
|
- <Route path="pruebas/aplicar" element={<PruebaAsignar/>} />
|
53
|
|
- </Route>
|
54
|
|
- )
|
55
|
|
- : ( <Route path="dashboard" element={<Navigate to='/'/>} />)
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
-
|
59
|
|
-
|
|
56
|
+ <Route path="/login" element={<Login/>} />
|
|
57
|
+ <Route
|
|
58
|
+ path="dashboard"
|
|
59
|
+ element={
|
|
60
|
+ <RequireAuth>
|
|
61
|
+ <Dashboard/>
|
|
62
|
+ </RequireAuth>
|
|
63
|
+ }
|
|
64
|
+ >
|
|
65
|
+ <Route path="home" element={<Home/>} />
|
|
66
|
+ <Route path="puestos" element={<Puestos/>} />
|
|
67
|
+ <Route path="perfil" element={<Profile/>} />
|
|
68
|
+ <Route path="contrasenas" element={<Contras/>} />
|
|
69
|
+ <Route path="expedientes" element={<Expedientes/>} />
|
|
70
|
+ <Route path="resultados" element={<Resultados/>} />
|
|
71
|
+ <Route path="configuraciones" element={<Configuracion/>} />
|
|
72
|
+ <Route path="historial" element={<Historial/>} />
|
|
73
|
+ <Route path="pruebas/listar" element={<Pruebas/>} />
|
|
74
|
+ <Route path="pruebas/crear" element={<PruebaNueva/>} />
|
|
75
|
+ <Route path="pruebas/aplicar" element={<PruebaAsignar/>} />
|
|
76
|
+ </Route>
|
60
|
77
|
<Route path="*" element={<NotFound/>}/>
|
61
|
78
|
|
62
|
79
|
</Routes>
|