From 4ffc3f216f327b7cd57acf1dd7aef55db5c6ee0c Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Tue, 23 Jul 2024 13:40:01 +0800 Subject: [PATCH] Admin verification --- .../AdministratorNavigationPanel.tsx | 59 +++++++++++++------ client/src/components/SignInModule.tsx | 9 ++- client/src/pages/AdministratorSpringboard.tsx | 5 +- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/client/src/components/AdministratorNavigationPanel.tsx b/client/src/components/AdministratorNavigationPanel.tsx index 5fefd33..991b9e2 100644 --- a/client/src/components/AdministratorNavigationPanel.tsx +++ b/client/src/components/AdministratorNavigationPanel.tsx @@ -3,6 +3,10 @@ import { Button, Card, CircularProgress, + Dropdown, + DropdownItem, + DropdownMenu, + DropdownTrigger, ScrollShadow, } from "@nextui-org/react"; import { @@ -14,6 +18,7 @@ import { GiftTopIcon, ChatBubbleOvalLeftIcon, ChevronLeftIcon, + ArrowRightStartOnRectangleIcon, } from "../icons"; import EcoconnectFullLogo from "./EcoconnectFullLogo"; import { retrieveUserInformation } from "../security/users"; @@ -176,26 +181,42 @@ export default function AdministratorNavigationPanel() {
-
- - + + + + } + color="danger" + title="Sign out" + onPress={() => { + localStorage.clear(); + window.location.reload(); + }} + /> + + )} diff --git a/client/src/components/SignInModule.tsx b/client/src/components/SignInModule.tsx index 763d136..9437c40 100644 --- a/client/src/components/SignInModule.tsx +++ b/client/src/components/SignInModule.tsx @@ -7,6 +7,7 @@ import NextUIFormikInput from "./NextUIFormikInput"; import { useNavigate } from "react-router-dom"; import { ChevronLeftIcon } from "../icons"; import { popErrorToast } from "../utilities"; +import { retrieveUserInformation } from "../security/users"; const validationSchema = Yup.object({ email: Yup.string() @@ -39,7 +40,13 @@ export default function SignInModule() { .post(config.serverAddress + "/users/login", values) .then((response) => { localStorage.setItem("accessToken", response.data.accessToken); - navigate("/springboard/"); + retrieveUserInformation().then((value) => { + if (value.accountType == 2) { + navigate("/admin"); + } else { + navigate("/springboard/"); + } + }); }) .catch((error) => { popErrorToast(error); diff --git a/client/src/pages/AdministratorSpringboard.tsx b/client/src/pages/AdministratorSpringboard.tsx index 3f32a53..8374b7a 100644 --- a/client/src/pages/AdministratorSpringboard.tsx +++ b/client/src/pages/AdministratorSpringboard.tsx @@ -29,9 +29,12 @@ export default function AdministratorSpringboard() { useEffect(() => { retrieveUserInformation() .then((response) => { + if (response.accountType != 2) { + navigate("/"); + } setUserInformation(response); }) - .catch((_) => { + .catch(() => { navigate("/signin"); }); return;