implement user authentication with login functionality and database integration

This commit is contained in:
2025-08-18 21:47:20 +02:00
parent 817a1efcdd
commit 298bc81435
12 changed files with 384 additions and 38 deletions

View File

@@ -1,13 +1,6 @@
import React from "react";
import { myToast } from "../utils/toastify";
const Form3: React.FC = () => {
if (localStorage.getItem("borrowCode")) {
myToast("Ausleihe erfolgreich!", "success");
} else {
myToast("Ausleihe fehlgeschlagen!", "error");
}
const code = localStorage.getItem("borrowCode") ?? "—";
return (

View File

@@ -1,4 +1,5 @@
import React from "react";
import Cookies from "js-cookie";
const Header: React.FC = () => {
return (
@@ -9,6 +10,15 @@ const Header: React.FC = () => {
<p className="text-blue-500 mt-1 md:mt-2 text-base md:text-lg font-medium">
Schnell und unkompliziert Equipment reservieren
</p>
<button
onClick={() => {
Cookies.remove("token");
window.location.reload();
}}
className="text-blue-500 hover:underline"
>
Logout
</button>
</header>
);
};

View File

@@ -0,0 +1,74 @@
import React from "react";
import { useState } from "react";
import { loginUser } from "../utils/fetchData";
import { myToast } from "../utils/toastify";
type LoginFormProps = {
onLogin: () => void;
};
const LoginForm: React.FC<LoginFormProps> = ({ onLogin }) => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const handleSubmit = async (e: React.FormEvent) => {
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");
}
};
return (
<div className="bg-blue-950 min-h-screen">
<div className="max-w-sm mx-auto mt-20 bg-white rounded-xl shadow-lg p-8 border border-blue-100">
<h2 className="text-2xl font-bold text-blue-700 mb-6 text-center">
Login
</h2>
<form onSubmit={handleSubmit} className="space-y-5">
<div>
<label
htmlFor="username"
className="block text-sm font-medium text-gray-700 mb-1"
>
Username
</label>
<input
type="text"
onChange={(e) => setUsername(e.target.value)}
id="username"
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 px-3 py-2"
required
/>
</div>
<div>
<label
htmlFor="password"
className="block text-sm font-medium text-gray-700 mb-1"
>
Password
</label>
<input
onChange={(e) => setPassword(e.target.value)}
type="password"
id="password"
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 px-3 py-2"
required
/>
</div>
<button
type="submit"
className="w-full bg-blue-600 text-white font-bold py-2 px-4 rounded-md shadow hover:bg-blue-700 transition"
>
Login
</button>
</form>
</div>
</div>
);
};
export default LoginForm;

View File

@@ -1,7 +1,10 @@
import React from "react";
import Object from "./Object";
import { useEffect } from "react";
const Sidebar: React.FC = () => {
useEffect(() => {});
const items = JSON.parse(localStorage.getItem("allItems") || "[]");
return (
@@ -20,16 +23,16 @@ const Sidebar: React.FC = () => {
d="M16.5 7.5V4.75A2.25 2.25 0 0 0 14.25 2.5h-4.5A2.25 2.25 0 0 0 7.5 4.75V7.5m9 0h-9m9 0v11.75A2.25 2.25 0 0 1 14.25 21.5h-4.5A2.25 2.25 0 0 1 7.5 19.25V7.5m9 0h-9"
/>
</svg>
Ausleih-Übersicht
Geräte Übersicht
</h2>
<div className="space-y-4 flex-1 overflow-auto pr-1">
{items.map((item: any) => (
<div
key={item.id}
key={item.item_name}
className="bg-white/80 rounded-xl p-4 shadow hover:shadow-md transition"
>
<Object title={item.title} description={item.description} />
<Object title={item.item_name} description={"test"} />
</div>
))}
</div>