Skip to content

Commit

Permalink
fixes #168 auth and admin login (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaddockAime authored and Ishimwe7 committed Oct 10, 2024
1 parent aedc9c2 commit 3290dc7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/form/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/profileDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function ProfileDropdown({
<div
className="w-full p-3 flex flex-row align-center justify-start text-gray-900 dark:text-black -100 dark:hover:bg-gray-300 dark:hover:text-gray-900 hover:bg-gray-600 hover:rounded-b-[20px] hover:text-gray-100 "
onClick={() => {
localStorage.removeItem("access_token");
localStorage.clear();
}}
>
<Link
Expand Down
9 changes: 5 additions & 4 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ const LoginPage = (props: any) => {
}
`;

return authenticated && roleName === "applicant" ?
<Navigate to="/applicant" /> : authenticated && roleName === "superAdmin" ? <Navigate to="/" />
:
(
return authenticated && roleName === "applicant" ? (
<Navigate to="/applicant" />
) : authenticated && (roleName === "superAdmin" || roleName === "admin") ? (
<Navigate to="/admin" />
) : (
<>
<div className="flex items-center dark:bg-zinc-800 ">
<div
Expand Down
2 changes: 1 addition & 1 deletion src/pages/LogoutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon } from "@iconify/react";
const LogoutPage = () => {
const navigate = useNavigate();
const handleLogout = async (e: any) => {
localStorage.removeItem("access_token");
localStorage.clear();
navigate("/login");
};
return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PageNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const PageNotFound = () => {
<Link to="/applicant">
<button>Go to Applicant Dashboard</button>
</Link>
) : role === "superAdmin" ? (
) : (role === "superAdmin" || role === "admin") ? (
<Link to="/admin">
<button>Go back to Homepage</button>
</Link>
Expand Down
3 changes: 1 addition & 2 deletions src/redux/actions/axiosconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 3290dc7

Please sign in to comment.