diff --git a/src/admin/NewsManager.tsx b/src/admin/NewsManager.tsx index a658c613d..5a2b508b5 100644 --- a/src/admin/NewsManager.tsx +++ b/src/admin/NewsManager.tsx @@ -4,6 +4,8 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; +const apiBase = import.meta.env.VITE_API_URL; + type NewsItem = { id: number; title: string; @@ -31,7 +33,7 @@ const NewsManager = () => { const loadNews = async () => { try { - const res = await fetch("http://192.168.50.65:3000/api/news"); + const res = await fetch(`${apiBase}/api/news`); const data = await res.json(); setNews(data); } catch (err) { @@ -42,8 +44,8 @@ const NewsManager = () => { const handleCreateOrUpdateNews = async () => { const method = editMode ? "PUT" : "POST"; const url = editMode - ? `http://192.168.50.65:3000/api/news/${currentId}` - : `http://192.168.50.65:3000/api/news`; + ? `${apiBase}/api/news/${currentId}` + : `${apiBase}/api/news`; try { const res = await fetch(url, { @@ -89,7 +91,7 @@ const NewsManager = () => { if (!deleteId) return; try { - const res = await fetch(`http://192.168.50.65:3000/api/news/${deleteId}`, { + const res = await fetch(`${apiBase}/api/news/${deleteId}`, { method: "DELETE", }); diff --git a/src/admin/UserCreatePage.tsx b/src/admin/UserCreatePage.tsx index 16ab12a37..2e6cbad62 100644 --- a/src/admin/UserCreatePage.tsx +++ b/src/admin/UserCreatePage.tsx @@ -5,12 +5,13 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { useNavigate } from "react-router-dom"; import { useAuth } from "@/context/AuthContext"; - +const apiBase = import.meta.env.VITE_API_URL; const UserCreatePage = () => { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [role, setRole] = useState("user"); + const [email, setEmail] = useState(""); const { token } = useAuth(); const {isAuthenticated, isAdmin} = useAuth(); @@ -27,13 +28,13 @@ useEffect(() => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { - const res = await fetch("http://192.168.50.65:3000/api/users", { + const res = await fetch(`${apiBase}/api/users`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, - body: JSON.stringify({ username, password, role }), + body: JSON.stringify({ username, password, role, email }), }); if (!res.ok) { @@ -55,6 +56,13 @@ useEffect(() => {
+ setEmail(e.target.value)} + required + /> { const { id } = useParams<{ id: string }>(); const { token, isAuthenticated, isAdmin } = useAuth(); @@ -23,7 +25,7 @@ const UserEditPage = () => { useEffect(() => { const fetchUser = async () => { try { - const res = await fetch(`http://192.168.50.65:3000/api/users/${id}`, { + const res = await fetch(`${apiBase}/api/users/${id}`, { headers: { Authorization: `Bearer ${token}`, }, @@ -44,7 +46,7 @@ const UserEditPage = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { - await fetch(`http://192.168.50.65:3000/api/users/${id}`, { + await fetch(`${apiBase}/api/users/${id}`, { method: "PUT", headers: { "Content-Type": "application/json", diff --git a/src/admin/UserManagementPage.tsx b/src/admin/UserManagementPage.tsx index 58c4ffbfb..b5aba7720 100644 --- a/src/admin/UserManagementPage.tsx +++ b/src/admin/UserManagementPage.tsx @@ -6,7 +6,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from " import { useAuth } from "@/context/AuthContext"; import { useNavigate } from "react-router-dom"; - +const apiBase = import.meta.env.VITE_API_URL; interface User { id: number; @@ -33,7 +33,7 @@ useEffect(() => { useEffect(() => { const fetchUsers = async () => { try { - const res = await fetch("http://192.168.50.65:3000/api/users", { + const res = await fetch(`${apiBase}/api/users`, { headers: { Authorization: `Bearer ${token}`, }, @@ -52,7 +52,7 @@ useEffect(() => { if (!userToDelete) return; try { - await fetch(`http://192.168.50.65:3000/api/users/${userToDelete.id}`, { + await fetch(`${apiBase}/api/users/${userToDelete.id}`, { method: "DELETE", headers: { Authorization: `Bearer ${token}`, diff --git a/src/pages/AlleNeuigkeiten.tsx b/src/pages/AlleNeuigkeiten.tsx index 798339b5c..294001aaa 100644 --- a/src/pages/AlleNeuigkeiten.tsx +++ b/src/pages/AlleNeuigkeiten.tsx @@ -1,6 +1,8 @@ import { useEffect, useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +const apiBase = import.meta.env.VITE_API_URL; + type NewsItem = { id: number; title: string; @@ -14,7 +16,7 @@ const AlleNeuigkeitenPage = () => { const [news, setNews] = useState([]); useEffect(() => { - fetch("http://192.168.50.65:3000/api/news") + fetch(`${apiBase}/api/news`) .then((res) => res.json()) .then((data) => setNews(data)) .catch((err) => console.error("Fehler beim Laden der News:", err)); diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index 1a7d0b5fd..5527b2ae2 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -4,6 +4,8 @@ import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +const apiBase = import.meta.env.VITE_API_URL; + const LoginPage = () => { const [email, setEmail] = useState(""); // Wird eigentlich Username sein! const [password, setPassword] = useState(""); @@ -15,7 +17,7 @@ const LoginPage = () => { setError(""); try { - const res = await fetch("http://192.168.50.65:3000/api/login", { + const res = await fetch(`${apiBase}/api/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: email, password }),