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 (