Changeset c68150f for reactapp/src/App.js
- Timestamp:
- 10/27/22 17:35:03 (21 months ago)
- Branches:
- main
- Children:
- 3b6962d
- Parents:
- 8d83180
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/App.js
r8d83180 rc68150f 12 12 import AuthApi from "./api/AuthApi"; 13 13 import Cookies from "js-cookie"; 14 import axios from "./api/axios";15 import JSOG from "jsog";16 14 import NotFound from "./Pages/NotFound"; 15 import Topic from "./Pages/Topic"; 17 16 18 17 export default function App() { 19 18 const [auth, setAuth] = useState(false); 20 const [user, setUser] = useState(null);21 const [userLoaded, setUserLoaded] = useState(false);22 19 const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]); 23 20 const [authLoaded, setAuthLoaded] = useState(false); 24 25 const fetchUser = async () => {26 try {27 const response = await axios.get(28 "http://192.168.0.17:8080/secure/currentUser",29 { withCredentials: true }30 );31 var cyclicGraph = await response.data;32 var jsogStructure = JSOG.encode(cyclicGraph);33 cyclicGraph = JSOG.decode(jsogStructure);34 setUser(cyclicGraph);35 setUserLoaded(true);36 } catch (error) {37 console.log("Fetching error", error);38 }39 };40 21 41 22 const readCookie = async () => { … … 43 24 if (session) { 44 25 setAuth(true); 45 fetchUser();46 26 } else { 47 27 setAuth(false); … … 51 31 52 32 useEffect(() => { 33 document.title = "profesori.mk"; 53 34 readCookie(); 54 35 }, []); … … 69 50 <BrowserRouter> 70 51 <Routes> 71 <Route 72 path="/" 73 element={<Home user={user} userLoaded={userLoaded} />} 74 > 52 <Route path="/" element={<Home />}> 75 53 <Route path="login" element={<Login />}></Route> 76 54 <Route path="registration" element={<Registration />}></Route> 77 55 <Route path="professor"> 78 <Route 79 path=":professorId" 80 element={<Professor user={user} userLoaded={userLoaded} />} 81 /> 56 <Route path=":professorId" element={<Professor />} /> 82 57 </Route> 83 58 <Route path="university/:universityId" element={<University />} /> 84 59 <Route path="faculty/:facultyId" element={<Faculty />} /> 85 60 <Route path="subject/:subjectId" element={<Subject />} /> 61 <Route path="topic/:topicId" element={<Topic />} /> 86 62 <Route path="search" element={<SearchResults />}></Route> 87 63 <Route 88 64 path="user_dashboard" 89 65 element={ 90 <ProtectedRoute auth={auth}> 91 {<UserDashboard user={user} userLoaded={userLoaded} />} 92 </ProtectedRoute> 66 <ProtectedRoute auth={auth}>{<UserDashboard />}</ProtectedRoute> 93 67 } 94 68 ></Route>
Note:
See TracChangeset
for help on using the changeset viewer.