Error: decodeToken is not defined in Header.jsx

This commit is contained in:
ISA
2024-11-15 11:16:02 +01:00
parent 140444d046
commit f619d7b796
9 changed files with 105 additions and 29 deletions

View File

@@ -11,7 +11,8 @@ import firmwareUpdate from "./handlers/firmwareUpdate";
function decodeToken(token) {
try {
const payload = JSON.parse(atob(token)); // Direkt das Token decodieren
const base64Payload = token.split(".")[1];
const payload = JSON.parse(atob(base64Payload));
return payload;
} catch (error) {
console.error("Fehler beim Dekodieren des Tokens:", error);
@@ -20,6 +21,7 @@ function decodeToken(token) {
}
function KueModal({ showModal, onClose, slot, onModulNameChange }) {
const isAdminLoggedIn = useSelector((state) => state.auth.isAdminLoggedIn);
const [isAdmin, setIsAdmin] = useState(false);
const dispatch = useDispatch();
const [ids, setIds] = useState(Array(32).fill(""));
@@ -100,11 +102,14 @@ function KueModal({ showModal, onClose, slot, onModulNameChange }) {
const token = localStorage.getItem("token");
if (token) {
const decoded = decodeToken(token);
if (decoded && decoded.role === "Admin") {
if (decoded && decoded.role.toLowerCase() === "admin") {
setIsAdmin(true);
} else {
setIsAdmin(false);
}
}
}, [showModal]);
//------------------------------------------------------------------------------------------------------------
return (
<ReactModal
@@ -242,7 +247,7 @@ function KueModal({ showModal, onClose, slot, onModulNameChange }) {
<div className="flex justify-end bg-gray-100 p-4 rounded-b-lg">
{/* Bedingte Anzeige der Firmware-Update-Schaltfläche */}
{isAdmin && (
{isAdminLoggedIn && (
<button
onClick={() => firmwareUpdate(slot)}
className="bg-littwin-blue text-white p-2 rounded flex items-center mr-2"