diff --git a/src/components/ProtectedRoute.jsx b/src/components/ProtectedRoute.jsx index b4e58b9..37cbf14 100644 --- a/src/components/ProtectedRoute.jsx +++ b/src/components/ProtectedRoute.jsx @@ -7,8 +7,26 @@ const ProtectedRoute = ({ children }) => { const token = localStorage.getItem("token"); const navigate = useNavigate(); - const handleLogout = () => { + const handleLogout = async () => { + const token = localStorage.getItem("token"); + + if (!token) { + console.warn("No token found — skipping API logout."); + } else { + try { + await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/Auth/logout`, { + method: "POST", + headers: { + Authorization: `Bearer ${token}`, + }, + }); + } catch (err) { + console.error("Logout API error:", err); + } + } + localStorage.removeItem("token"); + localStorage.removeItem("role"); navigate("/login"); }; diff --git a/src/pages/Dashboard.jsx b/src/pages/Dashboard.jsx index fb280af..035387a 100644 --- a/src/pages/Dashboard.jsx +++ b/src/pages/Dashboard.jsx @@ -1,10 +1,20 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; const Dashboard = () => { + const [role, setRole] = useState(""); + + useEffect(() => { + const role = localStorage.getItem("role"); + if (role) { + setRole(role); + } + }, []); + return (
Welcome! You are logged in.
+ {role === "SUPER" &&You are SUPER
}