This repository has been archived on 2022-05-20. You can view files and clone it, but cannot push or open issues or pull requests.
Alley-HSBC-Frontend/src/ProtectedRoute.tsx
2022-03-30 04:02:48 -07:00

36 lines
1.0 KiB
TypeScript

import { useLocation, Outlet, Navigate } from "react-router-dom";
import useAuth from "./hooks/useAuth";
import Navbar from "./components/navbar/Navbar";
import Sidebar from "./components/sidebar/Sidebar";
import { Box } from "@mui/material";
const ProtectedRoute = () => {
const auth = useAuth();
const location = useLocation();
/* Temporary data */
// if (auth?.isLoggedIn != undefined && auth?.isLoggedIn == true) {
// store.dispatch(fetchMeetings(auth?.uuid));
// store.dispatch(fetchUsers(auth?.uuid));
// store.dispatch(fetchFavorites(auth?.uuid));
// store.dispatch(socketActions.startConnecting());
// }
return auth?.isLoggedIn ? (
<>
<Navbar />
<Box id="drawer-container" sx={{ display: "flex", height: "100%" }}>
<Box sx={{ flexGrow: 1 }}>
<Outlet />
</Box>
<Box>
<Sidebar />
</Box>
</Box>
</>
) : (
<Navigate to="/login" state={{ from: location }} replace />
);
};
export default ProtectedRoute;