Ignore:
Timestamp:
08/19/22 19:10:24 (2 years ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
6221ab6
Parents:
6eba109
Message:

added current user/logout in header, display karma on user dashboard, started add post functionality in react

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reactapp/src/App.js

    r6eba109 r702ca77  
    44import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
    55import Home from "./Pages/Home";
    6 import User from "./Pages/User";
     6import UserDashboard from "./Pages/UserDashboard";
    77import { useEffect, useState, useMemo } from "react";
    88import AuthApi from "./api/AuthApi";
     
    1212  const [auth, setAuth] = useState(false);
    1313  const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]);
     14  const [authLoaded, setAuthLoaded] = useState(false);
    1415
    15   const readCookie = () => {
     16  const readCookie = async () => {
    1617    const session = Cookies.get("JSESSIONID");
    1718    if (session) {
    1819      setAuth(true); // go stava true ako postoi takvo cookie (zasto auth=false na sekoe renderiranje)
     20    } else {
     21      setAuth(false);
    1922    }
     23    setAuthLoaded(true);
    2024  };
    2125
     
    2529
    2630  const ProtectedRoute = ({ auth, children }) => {
    27     if (!auth) {
    28       return <Navigate to="/login" replace />;
     31    if (authLoaded) {
     32      if (!auth) {
     33        return <Navigate to="/login" replace />;
     34      }
     35      return children;
     36    } else {
     37      return <div>се вчитува cookie...</div>;
    2938    }
    30     return children;
    3139  };
    3240
     
    4250            <Route path="search" element={<SearchResults />}></Route>
    4351            <Route
    44               path="user"
     52              path="user_dashboard"
    4553              element={
    4654                <ProtectedRoute auth={auth}>
    47                   <User />
     55                  <UserDashboard />
    4856                </ProtectedRoute>
    4957              }
Note: See TracChangeset for help on using the changeset viewer.