Changeset 6221ab6 for reactapp/src/App.js
- Timestamp:
- 08/20/22 21:12:04 (23 months ago)
- Branches:
- main
- Children:
- 2fcbde4
- Parents:
- 702ca77
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/App.js
r702ca77 r6221ab6 8 8 import AuthApi from "./api/AuthApi"; 9 9 import Cookies from "js-cookie"; 10 import axios from "./api/axios"; 11 import JSOG from "jsog"; 10 12 11 13 export default function App() { 12 14 const [auth, setAuth] = useState(false); 15 const [user, setUser] = useState(null); 16 const [userLoaded, setUserLoaded] = useState(false); 13 17 const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]); 14 18 const [authLoaded, setAuthLoaded] = useState(false); 19 20 const fetchUser = async () => { 21 try { 22 const response = await axios.get( 23 "http://192.168.0.19:8080/secure/currentUser", 24 { withCredentials: true } 25 ); 26 var cyclicGraph = await response.data; 27 var jsogStructure = JSOG.encode(cyclicGraph); 28 cyclicGraph = JSOG.decode(jsogStructure); 29 setUser(cyclicGraph); 30 setUserLoaded(true); 31 } catch (error) { 32 console.log("Fetching error", error); 33 } 34 }; 15 35 16 36 const readCookie = async () => { … … 18 38 if (session) { 19 39 setAuth(true); // go stava true ako postoi takvo cookie (zasto auth=false na sekoe renderiranje) 40 fetchUser(); 20 41 } else { 21 42 setAuth(false); … … 43 64 <BrowserRouter> 44 65 <Routes> 45 <Route path="/" element={<Home />}> 66 <Route 67 path="/" 68 element={<Home user={user} userLoaded={userLoaded} />} 69 > 46 70 <Route path="login" element={<Login />}></Route> 47 71 <Route path="professor"> 48 <Route path=":professorId" element={<Professor />} /> 72 <Route 73 path=":professorId" 74 element={<Professor user={user} userLoaded={userLoaded} />} 75 /> 49 76 </Route> 50 77 <Route path="search" element={<SearchResults />}></Route> … … 53 80 element={ 54 81 <ProtectedRoute auth={auth}> 55 <UserDashboard />82 {<UserDashboard user={user} userLoaded={userLoaded} />} 56 83 </ProtectedRoute> 57 84 }
Note:
See TracChangeset
for help on using the changeset viewer.