+
Kamu belum tergabung ke projek apapun
diff --git a/src/Pages/internify/intern/components/SidebarIntern.tsx b/src/Pages/internify/intern/components/SidebarIntern.tsx
index 04a8194..e5aab80 100644
--- a/src/Pages/internify/intern/components/SidebarIntern.tsx
+++ b/src/Pages/internify/intern/components/SidebarIntern.tsx
@@ -5,14 +5,14 @@ import { MdOutlineAssignment, MdLogout } from "react-icons/md";
import { HiUser } from "react-icons/hi2";
const navItems = [
- { label: "Home", icon: GrHomeRounded, path: "/intern" },
- { label: "List Projects", icon: MdOutlineAssignment, path: "/intern/projects" },
- { label: "Certificates", icon: Award, path: "/intern/certificates" },
+ { label: "Home", icon: GrHomeRounded, path: "/internship" },
+ { label: "List Projects", icon: MdOutlineAssignment, path: "/internship/projects" },
+ { label: "Certificates", icon: Award, path: "/internship/certificates" },
];
const prefItems = [
- { label: "Settings", icon: Settings, path: "/intern/settings" },
- { label: "FAQ", icon: HelpCircle, path: "/intern/faq" },
+ { label: "Settings", icon: Settings, path: "/internship/settings" },
+ { label: "FAQ", icon: HelpCircle, path: "/internship/faq" },
{ label: "Logout", icon: MdLogout, path: "/login-internify", danger: true, isLogout: true },
];
@@ -31,7 +31,7 @@ export default function SidebarIntern({ isOpen, closeSidebar }: SidebarProps) {
};
const handleLogout = () => {
- document.cookie = "token=; path=/; max-age=86400; SameSite=Strict";
+ document.cookie = "token=; Max-Age=0; path=/; SameSite=Strict";
closeSidebar();
navigate("/login-internify", { replace: true });
diff --git a/src/Pages/internify/mentor/components/SidebarMentor.tsx b/src/Pages/internify/mentor/components/SidebarMentor.tsx
index e246b4d..5630ffd 100644
--- a/src/Pages/internify/mentor/components/SidebarMentor.tsx
+++ b/src/Pages/internify/mentor/components/SidebarMentor.tsx
@@ -30,7 +30,7 @@ export default function SidebarMentor({ isOpen, closeSidebar }: SidebarProps) {
};
const handleLogout = () => {
- document.cookie = "token=; path=/; max-age=86400; SameSite=Strict";
+ document.cookie = "token=; Max-Age=0; path=/; SameSite=Strict";
closeSidebar();
navigate("/login-internify", { replace: true });
diff --git a/src/Pages/utils/PrivateRoute.tsx b/src/Pages/utils/PrivateRoute.tsx
index f10f5a5..5073ec7 100644
--- a/src/Pages/utils/PrivateRoute.tsx
+++ b/src/Pages/utils/PrivateRoute.tsx
@@ -10,7 +10,7 @@ const PrivateRoute = () => {
useEffect(() => {
if (!token) {
- navigate("/humic-20242025-2");
+ navigate("/login-admin");
}
}, [navigate, token]);
diff --git a/src/Pages/utils/ProtectedRoute.tsx b/src/Pages/utils/ProtectedRoute.tsx
index 084f6af..4613231 100644
--- a/src/Pages/utils/ProtectedRoute.tsx
+++ b/src/Pages/utils/ProtectedRoute.tsx
@@ -1,42 +1,30 @@
import { Outlet, Navigate } from "react-router-dom";
-import { decodeJWT } from "./decodeJWT";
+import { decodeJWT } from "../utils/decodeJWT";
-type Role = "intern" | "admin" | "mentor";
-interface RouteProps {
- allowedRoles?: Role[];
+interface PrivateRouteProps {
+ allowedRoles?: ("intern" | "admin" | "mentor")[];
}
-interface JwtPayload {
- id: string;
- email: string;
- role: "intern" | "mentor" | "admin";
- signature?: string | null;
- iat: number;
- exp: number;
-}
-
-const ProtectedRoutes = ({ allowedRoles }: RouteProps) => {
- const token = sessionStorage.getItem("token");
+const ProtectedRoutes = ({ allowedRoles }: PrivateRouteProps) => {
+ const token = document.cookie
+ .split("; ")
+ .find((row) => row.startsWith("token="))
+ ?.split("=")[1];
if (!token) {
return
;
}
- const decoded = decodeJWT
(token);
- const userRole = decoded?.role as Role | undefined;
+ const decoded = decodeJWT(token);
+ const userRole = decoded?.role as "intern" | "admin" | "mentor" | undefined;
if (!userRole) {
- sessionStorage.removeItem("token");
return ;
}
if (allowedRoles && !allowedRoles.includes(userRole)) {
- return (
-
- );
+ if (userRole === "admin" || userRole === "mentor") return ;
+ if (userRole === "intern") return ;
}
return ;
diff --git a/src/lib/api.ts b/src/lib/api.ts
index fb099f1..83150f3 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1,18 +1,20 @@
import axios from "axios";
-export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
+export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string;
const api = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL,
});
api.interceptors.request.use((config) => {
- const token = sessionStorage.getItem("token");
+ const token = document.cookie
+ .split("; ")
+ .find((row) => row.startsWith("token="))
+ ?.split("=")[1];
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
-
return config;
});