"use client"; import { cn } from "@/lib/utils"; import { signIn } from "@/lib/actions/auth"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState, useEffect } from "react"; export function LoginForm({ className, ...props }: React.ComponentPropsWithoutRef<"div">) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const [messageParam, setMessageParam] = useState(null); const [errorParam, setErrorParam] = useState(null); const router = useRouter(); useEffect(() => { const params = new URLSearchParams(window.location.search); setMessageParam(params.get('message')); setErrorParam(params.get('error')); }, []); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(null); const nextParam = typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('next') : null; try { const res = await signIn(email, password); if (!res.success) { setError(res.error || "An error occurred"); return; } if (nextParam) { router.push(nextParam); } else if (res.role === "admin") { router.push("/admin/einstellungen"); } else { router.push("/my-customers"); } } catch (error: unknown) { setError(error instanceof Error ? error.message : "An error occurred"); } finally { setIsLoading(false); } }; return (
Login Enter your email below to login to your account
setEmail(e.target.value)} />
Forgot your password?
setPassword(e.target.value)} />
{errorParam === "gesperrt" && (

🚫 Ihr Konto wurde gesperrt. Bitte wenden Sie sich an den Administrator.

)} {messageParam === "concurrent" && (

Sie wurden abgemeldet, da Sie sich an einem anderen Gerät angemeldet haben.

)} {error &&

{error}

}
); }