Added improved login and logout route for the frontend. The frontend page now doesn't have to reload.
This commit is contained in:
@@ -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<HeaderProps> = ({ onLogout }) => {
|
||||
return (
|
||||
<header className="mb-6 md:mb-10">
|
||||
<h1 className="text-3xl md:text-4xl font-extrabold text-blue-800 tracking-tight drop-shadow-sm">
|
||||
@@ -11,12 +14,8 @@ const Header: React.FC = () => {
|
||||
Schnell und unkompliziert Equipment reservieren
|
||||
</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
Cookies.remove("token");
|
||||
localStorage.removeItem("allItems");
|
||||
|
||||
window.location.reload();
|
||||
}}
|
||||
type="button"
|
||||
onClick={onLogout}
|
||||
className="text-blue-500 hover:underline"
|
||||
>
|
||||
Logout
|
||||
|
@@ -15,7 +15,6 @@ const LoginForm: React.FC<LoginFormProps> = ({ onLogin }) => {
|
||||
e.preventDefault();
|
||||
const result = await loginUser(username, password);
|
||||
if (result.success) {
|
||||
myToast("Login successful!", "success");
|
||||
onLogin();
|
||||
} else {
|
||||
myToast("Login failed. Please check your credentials.", "error");
|
||||
|
@@ -1,11 +1,22 @@
|
||||
import React from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Object from "./Object";
|
||||
import { useEffect } from "react";
|
||||
import { ALL_ITEMS_UPDATED_EVENT } from "../utils/fetchData";
|
||||
|
||||
const Sidebar: React.FC = () => {
|
||||
useEffect(() => {});
|
||||
const [items, setItems] = useState<any[]>(
|
||||
JSON.parse(localStorage.getItem("allItems") || "[]")
|
||||
);
|
||||
|
||||
const items = JSON.parse(localStorage.getItem("allItems") || "[]");
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
const next = JSON.parse(localStorage.getItem("allItems") || "[]");
|
||||
setItems(next);
|
||||
};
|
||||
// Update immediately in case data changed before this mounted
|
||||
handler();
|
||||
window.addEventListener(ALL_ITEMS_UPDATED_EVENT, handler);
|
||||
return () => window.removeEventListener(ALL_ITEMS_UPDATED_EVENT, handler);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<aside className="w-full md:w-80 md:min-h-screen bg-white/90 backdrop-blur md:border-r border-blue-100 shadow-xl flex flex-col p-6">
|
||||
|
Reference in New Issue
Block a user