summaryrefslogtreecommitdiff
path: root/microservices/04-react-app/src
diff options
context:
space:
mode:
Diffstat (limited to 'microservices/04-react-app/src')
-rw-r--r--microservices/04-react-app/src/App.jsx4
-rw-r--r--microservices/04-react-app/src/components/Navbar.jsx3
2 files changed, 5 insertions, 2 deletions
diff --git a/microservices/04-react-app/src/App.jsx b/microservices/04-react-app/src/App.jsx
index aedd87e..956e60a 100644
--- a/microservices/04-react-app/src/App.jsx
+++ b/microservices/04-react-app/src/App.jsx
@@ -11,7 +11,7 @@ import AdminPage from "./pages/AdminPage";
import { useAuth } from "./contexts/AuthContext";
function App() {
- const { isAdmin } = useAuth();
+ const { isLoggedIn, isAdmin } = useAuth();
return (
<div className="app">
@@ -20,7 +20,7 @@ function App() {
<Routes>
<Route index element={<HomePage />} />
<Route path="about" element={<AboutPage />} />
- <Route path="posts" element={<PostList />} />
+ <Route path="posts" element={isLoggedIn() ? <PostList /> : <Navigate to="/" />} />
<Route path="admin" element={isAdmin() ? <AdminPage /> : <Navigate to="/" />} />
diff --git a/microservices/04-react-app/src/components/Navbar.jsx b/microservices/04-react-app/src/components/Navbar.jsx
index 9697c73..bc79138 100644
--- a/microservices/04-react-app/src/components/Navbar.jsx
+++ b/microservices/04-react-app/src/components/Navbar.jsx
@@ -29,11 +29,14 @@ const Navbar = () => {
About
</NavLink>
</li>
+
+ {isLoggedIn() && (
<li>
<NavLink className="nav-link" to="/posts" end>
Posts
</NavLink>
</li>
+ )}
<RoleGuard allowedRoles={['ADMIN']}>
<li>