Ignore:
Timestamp:
08/20/22 21:12:04 (23 months ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
2fcbde4
Parents:
702ca77
Message:

finished add post func. in react, fixed user dashboard details not loading upon login redirect

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reactapp/src/App.js

    r702ca77 r6221ab6  
    88import AuthApi from "./api/AuthApi";
    99import Cookies from "js-cookie";
     10import axios from "./api/axios";
     11import JSOG from "jsog";
    1012
    1113export default function App() {
    1214  const [auth, setAuth] = useState(false);
     15  const [user, setUser] = useState(null);
     16  const [userLoaded, setUserLoaded] = useState(false);
    1317  const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]);
    1418  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  };
    1535
    1636  const readCookie = async () => {
     
    1838    if (session) {
    1939      setAuth(true); // go stava true ako postoi takvo cookie (zasto auth=false na sekoe renderiranje)
     40      fetchUser();
    2041    } else {
    2142      setAuth(false);
     
    4364      <BrowserRouter>
    4465        <Routes>
    45           <Route path="/" element={<Home />}>
     66          <Route
     67            path="/"
     68            element={<Home user={user} userLoaded={userLoaded} />}
     69          >
    4670            <Route path="login" element={<Login />}></Route>
    4771            <Route path="professor">
    48               <Route path=":professorId" element={<Professor />} />
     72              <Route
     73                path=":professorId"
     74                element={<Professor user={user} userLoaded={userLoaded} />}
     75              />
    4976            </Route>
    5077            <Route path="search" element={<SearchResults />}></Route>
     
    5380              element={
    5481                <ProtectedRoute auth={auth}>
    55                   <UserDashboard />
     82                  {<UserDashboard user={user} userLoaded={userLoaded} />}
    5683                </ProtectedRoute>
    5784              }
Note: See TracChangeset for help on using the changeset viewer.