diff --git a/client/src/App.tsx b/client/src/App.tsx index c8a40aa..b8502a8 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,5 +1,10 @@ import { CookiesProvider } from "react-cookie"; -import { Route, BrowserRouter as Router, Routes } from "react-router-dom"; +import { + Navigate, + Route, + BrowserRouter as Router, + Routes, +} from "react-router-dom"; import { Admin } from "./components/admin/Admin"; import { CatchAll } from "./components/CatchAll"; @@ -41,6 +46,15 @@ const App = () => { } /> + + } + /> } />} diff --git a/client/src/components/ProtectedRoute.tsx b/client/src/components/ProtectedRoute.tsx index 1cd8fda..3c880a7 100644 --- a/client/src/components/ProtectedRoute.tsx +++ b/client/src/components/ProtectedRoute.tsx @@ -17,7 +17,13 @@ export const ProtectedRoute = ({ const roles = Array.isArray(allowedRoles) ? allowedRoles : [allowedRoles]; const isValidRole = getIsValidRole(roles, role); - return currentUser && isValidRole ? element : ; + return currentUser && isValidRole ? ( + element + ) : currentUser ? ( + + ) : ( + + ); }; /** diff --git a/client/src/components/dashboard/Dashboard.tsx b/client/src/components/dashboard/Dashboard.tsx index 9567121..3388978 100644 --- a/client/src/components/dashboard/Dashboard.tsx +++ b/client/src/components/dashboard/Dashboard.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; import { Button, + Link as ChakraLink, Heading, Table, TableCaption, @@ -15,6 +16,8 @@ import { VStack, } from "@chakra-ui/react"; +import { Link } from "react-router-dom"; + import { useAuthContext } from "../../contexts/hooks/useAuthContext"; import { useBackendContext } from "../../contexts/hooks/useBackendContext"; import { useRoleContext } from "../../contexts/hooks/useRoleContext"; @@ -49,7 +52,19 @@ export const Dashboard = () => { Dashboard - Signed in as {currentUser?.email} + + Signed in as {currentUser?.email} ( + {role === "admin" ? "Admin" : "User"}) + + + {role === "admin" ? ( + + Go to Admin Page + + ) : null} diff --git a/client/src/components/login/Login.tsx b/client/src/components/login/Login.tsx index bb280d7..b8eabe3 100644 --- a/client/src/components/login/Login.tsx +++ b/client/src/components/login/Login.tsx @@ -65,6 +65,8 @@ export const Login = () => { email: data.email, password: data.password, }); + + navigate("/dashboard"); } catch (err) { const errorCode = err.code; const firebaseErrorMsg = err.message; diff --git a/package.json b/package.json index 58f55bc..160af1d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "packageManager": "yarn@1.22.22", "engines": { - "yarn": "^1.22.22", + "yarn": "^1.22.0", "node": ">=18" } }