|
@@ -1,5 +1,5 @@
|
1
|
1
|
import React, {useEffect} from 'react'
|
2
|
|
-import { Routes, Route, Navigate, useNavigate, useLocation } from "react-router-dom";
|
|
2
|
+import { Routes, Route,useNavigate } from "react-router-dom";
|
3
|
3
|
|
4
|
4
|
import { Dashboard } from "./Dashboard";
|
5
|
5
|
import { Login } from '../Pages/Login'
|
|
@@ -17,25 +17,7 @@ import { NotFound } from '../Pages/404'
|
17
|
17
|
import { Profile } from '../Pages/Profile'
|
18
|
18
|
|
19
|
19
|
import useAuth from '../Auth/useAuth'
|
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
|
|
-
|
|
20
|
+import RequireAuth from '../Components/PrivateRoute'
|
39
|
21
|
|
40
|
22
|
export default function MyRoutes () {
|
41
|
23
|
|
|
@@ -43,17 +25,15 @@ export default function MyRoutes () {
|
43
|
25
|
let navigate = useNavigate()
|
44
|
26
|
|
45
|
27
|
useEffect(() => {
|
46
|
|
- console.log('usse fec check user')
|
47
|
28
|
if(!auth.isLogged()){
|
48
|
29
|
return navigate('login')
|
49
|
|
- }else{
|
50
|
|
- return navigate('dashboard/home')
|
51
|
|
- }
|
52
|
|
- },[auth,navigate])
|
|
30
|
+ }
|
|
31
|
+ }, [auth, navigate])
|
53
|
32
|
|
54
|
33
|
return(
|
55
|
34
|
<Routes>
|
56
|
|
- <Route path="/login" element={<Login/>} />
|
|
35
|
+
|
|
36
|
+ <Route path="login" element={<Login/>} />
|
57
|
37
|
<Route
|
58
|
38
|
path="dashboard"
|
59
|
39
|
element={
|