Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
fix: route protection bug fixed (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
SHUHAIB-T authored Mar 9, 2024
2 parents 2f546ba + c5961d2 commit 4c1ab4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Auth/Authenticate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Authenticate() {
if (parseUser?.role === "ADMIN") {
navigate("/admin");
} else if (parseUser?.role === "USER") {
navigate("/");
navigate("/home");
}
}, [parseUser, navigate]);
return <>{!user ? <Outlet /> : null}</>;
Expand Down
6 changes: 5 additions & 1 deletion client/src/routes/UserRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lazy, Suspense } from "react";
import { Route, Routes } from "react-router";
import Loader from "../components/Loader/Loader1/Loader";
import Authenticate from "../components/Auth/Authenticate";
import Protect from "../components/Auth/Protect";

const Home = lazy(() => import("../pages/UserPages/Home/Home"));
const Signup = lazy(() => import("../pages/UserPages/Signup/Signup"));
Expand All @@ -12,11 +13,14 @@ export default function UserRoute() {
<>
<Suspense fallback={<Loader />}>
<Routes>
<Route path={"/"} element={<Home />} />
<Route element={<Authenticate />}>
<Route path={"/"} element={<Home />} />
<Route path={"/signup"} element={<Signup />} />
<Route path={"/login"} element={<Login />} />
</Route>
<Route element={<Protect role="USER" />}>
<Route path={"/home"} element={<Home />} />
</Route>
</Routes>
</Suspense>
</>
Expand Down

0 comments on commit 4c1ab4d

Please sign in to comment.