diff --git a/client/src/App.tsx b/client/src/App.tsx index c4ff039..41ec0df 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -13,6 +13,7 @@ import LivePage from "@/pages/LivePage"; import PlayerPage from "@/pages/PlayerPage"; import KuenstlerPage from "@/pages/KuenstlerPage"; import AdminPage from "@/pages/admin"; +import LoginPage from "@/pages/login"; import PrivacyPolicy from "@/pages/PrivacyPolicy"; import TermsOfService from "@/pages/TermsOfService"; import Impressum from "@/pages/Impressum"; @@ -29,6 +30,7 @@ function Router() { + diff --git a/client/src/pages/admin.tsx b/client/src/pages/admin.tsx index 032edd2..1ec03d4 100644 --- a/client/src/pages/admin.tsx +++ b/client/src/pages/admin.tsx @@ -29,7 +29,7 @@ export default function AdminPage() { // Redirect if not admin if (!authLoading && (!isAuthenticated || !isAdmin)) { - window.location.href = "/api/login"; + window.location.href = "/login"; return null; } @@ -59,7 +59,7 @@ export default function AdminPage() { window.location.href = "/api/logout"} + onClick={async () => { await fetch("/api/auth/logout", { method: "POST", credentials: "include" }); window.location.href = "/login"; }} className="text-white border-white/20 hover:bg-white/10" > Logout diff --git a/client/src/pages/login.tsx b/client/src/pages/login.tsx new file mode 100644 index 0000000..7caff56 --- /dev/null +++ b/client/src/pages/login.tsx @@ -0,0 +1,89 @@ +import { useState } from "react"; +import { useLocation } from "wouter"; +import { useQueryClient } from "@tanstack/react-query"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Loader2, LogIn } from "lucide-react"; + +export default function LoginPage() { + const [, navigate] = useLocation(); + const queryClient = useQueryClient(); + + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(""); + + async function submit(e: React.FormEvent) { + e.preventDefault(); + setError(""); + setBusy(true); + try { + const res = await fetch("/api/auth/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + credentials: "include", + body: JSON.stringify({ email: email.trim(), password }), + }); + if (!res.ok) { + const body = await res.json().catch(() => ({})); + throw new Error(body.error || "Anmeldung fehlgeschlagen"); + } + await queryClient.invalidateQueries({ queryKey: ["/api/auth/user"] }); + await queryClient.refetchQueries({ queryKey: ["/api/auth/user"] }); + navigate("/admin"); + } catch (err: any) { + setError(err?.message || "Anmeldung fehlgeschlagen"); + } finally { + setBusy(false); + } + } + + return ( + + + + + + Anmeldung + + + + + + E-Mail + setEmail(e.target.value)} + required + className="bg-white/10 border-white/20 text-white" + /> + + + Passwort + setPassword(e.target.value)} + required + className="bg-white/10 border-white/20 text-white" + /> + + + {error && {error}} + + + {busy ? : } + {busy ? "Anmeldung läuft…" : "Anmelden"} + + + + + + ); +} diff --git a/server/routes.ts b/server/routes.ts index da3375e..de0fa33 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1684,28 +1684,12 @@ Sitemap: ${baseUrl}/sitemap.xml // ===== ADMIN ROUTES ===== // Auth route to get current user - app.get('/api/auth/user', isAuthenticated, async (req: any, res) => { + app.get('/api/auth/user', authenticate, async (req, res) => { try { - // Import the generateDeterministicUUID function from replitAuth - const { createHash } = await import('crypto'); - const generateDeterministicUUID = (replitId: string): string => { - const hash = createHash('sha256').update(`replit_${replitId}`).digest('hex'); - return [ - hash.substring(0, 8), - hash.substring(8, 12), - '4' + hash.substring(13, 16), - (parseInt(hash.substring(16, 17), 16) & 0x3 | 0x8).toString(16) + hash.substring(17, 20), - hash.substring(20, 32) - ].join('-'); - }; - - const userId = generateDeterministicUUID(req.user.claims.sub); - const user = await storage.getUser(userId); + const user = await storage.getUser(req.session.userId!); if (!user) { return res.status(404).json({ message: "User not found" }); } - - // Remove sensitive data const { passwordHash, ...userResponse } = user; res.json(userResponse); } catch (error) {
{error}