From bd88713468375e6c3500885825e57475fd0040e4 Mon Sep 17 00:00:00 2001 From: Saddock Kabandana Date: Fri, 4 Oct 2024 09:43:39 +0200 Subject: [PATCH] fixes #168 auth and admin login (#169) --- src/components/form/SignInForm.tsx | 2 +- src/components/profileDropdown.tsx | 2 +- src/pages/LoginPage.tsx | 9 +++++---- src/pages/LogoutPage.tsx | 2 +- src/pages/PageNotFound.tsx | 2 +- src/redux/actions/axiosconfig.ts | 3 +-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/form/SignInForm.tsx b/src/components/form/SignInForm.tsx index a8a5c17c4..0b02d7d06 100644 --- a/src/components/form/SignInForm.tsx +++ b/src/components/form/SignInForm.tsx @@ -60,7 +60,7 @@ const LoginForm = () => { const role = localStorage.getItem("roleName") as string; if (role === "applicant") { navigate("/applicant"); - } else if (role === "superAdmin") { + } else if (role === "superAdmin" || role === "admin") { navigate("/admin"); } else { const searchParams = new URLSearchParams(location.search); diff --git a/src/components/profileDropdown.tsx b/src/components/profileDropdown.tsx index 638778dc5..62e995589 100755 --- a/src/components/profileDropdown.tsx +++ b/src/components/profileDropdown.tsx @@ -49,7 +49,7 @@ function ProfileDropdown({
{ - localStorage.removeItem("access_token"); + localStorage.clear(); }} > { } `; - return authenticated && roleName === "applicant" ? - : authenticated && roleName === "superAdmin" ? - : - ( + return authenticated && roleName === "applicant" ? ( + + ) : authenticated && (roleName === "superAdmin" || roleName === "admin") ? ( + + ) : ( <>
{ const navigate = useNavigate(); const handleLogout = async (e: any) => { - localStorage.removeItem("access_token"); + localStorage.clear(); navigate("/login"); }; return ( diff --git a/src/pages/PageNotFound.tsx b/src/pages/PageNotFound.tsx index baa8b4962..769e1816e 100644 --- a/src/pages/PageNotFound.tsx +++ b/src/pages/PageNotFound.tsx @@ -13,7 +13,7 @@ const PageNotFound = () => { - ) : role === "superAdmin" ? ( + ) : (role === "superAdmin" || role === "admin") ? ( diff --git a/src/redux/actions/axiosconfig.ts b/src/redux/actions/axiosconfig.ts index aba173562..ae5d6cc1b 100755 --- a/src/redux/actions/axiosconfig.ts +++ b/src/redux/actions/axiosconfig.ts @@ -8,8 +8,7 @@ config.interceptors.request.use( (config) => { const token = localStorage.getItem("access_token"); if (token) { - config.headers = config.headers || {}; - config.headers["Authorization"] = `Bearer ${token}`; + config.headers["Authorization"] = `${token}`; } return config; },