diff --git a/client/src/Routes.tsx b/client/src/Routes.tsx
index 5591968..15dd2c0 100644
--- a/client/src/Routes.tsx
+++ b/client/src/Routes.tsx
@@ -1,11 +1,9 @@
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { ProtectedRoute } from "./components";
-import { AuthContextState, useAuth } from "./lib/hooks";
+import { DashboardPage, LogoutPage } from "./pages";
import { LoginPage } from "./pages/LoginPage";
export const Routes = () => {
- const { isLoggedIn } = useAuth() as AuthContextState;
-
// Define public routes accessible to all users
const routesForPublic = [
{
@@ -20,6 +18,22 @@ export const Routes = () => {
// Define routes accessible only to authenticated users
const routesForAuthenticatedOnly = [
+ {
+ path: "/profile",
+ element: (
+
+ Profile
+
+ ),
+ },
+ {
+ path: "/logout",
+ element: (
+
+
+
+ ),
+ },
{
path: "/admin",
element: , // Wrap the component in ProtectedRoute
@@ -28,14 +42,6 @@ export const Routes = () => {
path: "",
element:
Dashboard
,
},
- {
- path: "profile",
- element: User Profile
,
- },
- {
- path: "logout",
- element: Logout
,
- },
],
},
];
@@ -44,7 +50,7 @@ export const Routes = () => {
const routesForNotAuthenticatedOnly = [
{
path: "/",
- element: Home Page
,
+ Component: DashboardPage,
},
{
path: "/login",
@@ -55,7 +61,7 @@ export const Routes = () => {
// Combine and conditionally include routes based on authentication status
const router = createBrowserRouter([
...routesForPublic,
- ...(!isLoggedIn ? routesForNotAuthenticatedOnly : []),
+ ...routesForNotAuthenticatedOnly,
...routesForAuthenticatedOnly,
]);
diff --git a/client/src/components/ProtectedRoute/ProtectedRoute.tsx b/client/src/components/ProtectedRoute/ProtectedRoute.tsx
index baf00a5..bc4a897 100644
--- a/client/src/components/ProtectedRoute/ProtectedRoute.tsx
+++ b/client/src/components/ProtectedRoute/ProtectedRoute.tsx
@@ -1,28 +1,30 @@
import { useIsLoggedIn } from "@/lib/hooks";
import React from "react";
import { Navigate } from "react-router-dom";
+import { LoadingOverlay } from "../LoadingOverlay";
type ProctectRouteProps = {
children?: React.ReactNode;
};
export const ProtectedRoute = ({ children }: ProctectRouteProps) => {
- const { isSuccess, data } = useIsLoggedIn();
+ const { isPending, isSuccess, data: { authenticated, redirectTo } = {} } = useIsLoggedIn();
- if (isSuccess && data) {
- const { authenticated, redirectTo } = data;
- if (authenticated) {
- return (
-
- );
- }
+ if (isPending) {
+ return ;
}
- return children;
+ if (isSuccess && !authenticated) {
+ return (
+
+ );
+ }
+
+ return <>{children ?? null}>;
};
diff --git a/client/src/components/UeckoLogo/UeckoLogo.tsx b/client/src/components/UeckoLogo/UeckoLogo.tsx
index bfb77d4..806c70c 100644
--- a/client/src/components/UeckoLogo/UeckoLogo.tsx
+++ b/client/src/components/UeckoLogo/UeckoLogo.tsx
@@ -1,5 +1,11 @@
-export const UeckoLogo = ({ className }: { className: string }) => (
-