From 8fbcd069b56f0cd82e9800220ae213874a4a96d2 Mon Sep 17 00:00:00 2001
From: "theis.gaedigk"
Date: Tue, 19 Aug 2025 14:21:30 +0200
Subject: [PATCH] Added improved login and logout route for the frontend. The
frontend page now doesn't have to reload.
---
frontend/src/App.tsx | 35 ++++++++++++---------------
frontend/src/components/Header.tsx | 15 ++++++------
frontend/src/components/LoginForm.tsx | 1 -
frontend/src/components/Sidebar.tsx | 19 ++++++++++++---
frontend/src/layout/Layout.tsx | 20 +++------------
frontend/src/main.tsx | 29 ++++++++++++++++------
frontend/src/utils/fetchData.ts | 5 ++++
7 files changed, 68 insertions(+), 56 deletions(-)
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index fdd45e2..bb84940 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -6,14 +6,17 @@ import Form2 from "./components/Form2";
import Form3 from "./components/Form3";
import LoginForm from "./components/LoginForm";
import Cookies from "js-cookie";
-import { ToastContainer } from "react-toastify";
+import { fetchAllData, ALL_ITEMS_UPDATED_EVENT } from "./utils/fetchData";
+import { myToast } from "./utils/toastify";
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
- if (Cookies.get("token")) {
+ const token = Cookies.get("token");
+ if (token) {
setIsLoggedIn(true);
+ fetchAllData(token);
}
localStorage.setItem("borrowableItems", JSON.stringify([]));
@@ -21,8 +24,17 @@ function App() {
}, []);
// Mock flow without real logic: show the three sections stacked for design preview
+ const handleLogout = () => {
+ Cookies.remove("token");
+ localStorage.removeItem("allItems");
+ // Let listeners refresh from empty state
+ window.dispatchEvent(new Event(ALL_ITEMS_UPDATED_EVENT));
+ myToast("Logged out successfully!", "success");
+ setIsLoggedIn(false);
+ };
+
return isLoggedIn ? (
-
+
@@ -32,22 +44,7 @@ function App() {
) : (
- <>
- setIsLoggedIn(true)} />
-
- >
+ setIsLoggedIn(true)} />
);
}
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index fcd95d2..e891823 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -1,7 +1,10 @@
import React from "react";
-import Cookies from "js-cookie";
-const Header: React.FC = () => {
+type HeaderProps = {
+ onLogout: () => void;
+};
+
+const Header: React.FC = ({ onLogout }) => {
return (
@@ -11,12 +14,8 @@ const Header: React.FC = () => {
Schnell und unkompliziert Equipment reservieren