Added improved login and logout route for the frontend. The frontend page now doesn't have to reload.

This commit is contained in:
2025-08-19 14:21:30 +02:00
parent 06f84cddc4
commit 8fbcd069b5
7 changed files with 68 additions and 56 deletions

View File

@@ -1,6 +1,9 @@
import Cookies from "js-cookie";
import { myToast } from "./toastify";
// Event name used to notify the app when the list of items has been updated
export const ALL_ITEMS_UPDATED_EVENT = "allItemsUpdated";
export const fetchAllData = async (token: string | undefined) => {
if (!token) return;
try {
@@ -19,6 +22,8 @@ export const fetchAllData = async (token: string | undefined) => {
const data = await response.json();
localStorage.setItem("allItems", JSON.stringify(data));
// Notify listeners (e.g., Sidebar) that items have been updated
window.dispatchEvent(new Event(ALL_ITEMS_UPDATED_EVENT));
} catch (error) {
myToast("An error occurred", "error");
}